File tree Expand file tree Collapse file tree 8 files changed +30
-7
lines changed Expand file tree Collapse file tree 8 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,8 @@ pub enum Error {
96
96
BadStructMemberType ,
97
97
#[ error( "Cannot read into non-pointer" ) ]
98
98
BadReadParameter ,
99
+ #[ error( "Invalid block size" ) ]
100
+ InvalidBlockSize ,
99
101
100
102
#[ error( "{0}" ) ]
101
103
Util ( #[ from] util:: Error ) ,
Original file line number Diff line number Diff line change @@ -123,7 +123,10 @@ impl Unmarshal for DLRRReportBlock {
123
123
}
124
124
125
125
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
126
- let block_length = xr_header. block_length * 4 ;
126
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
127
+ Some ( length) => length,
128
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
129
+ } ;
127
130
if block_length % DLRR_REPORT_LENGTH != 0 || raw_packet. remaining ( ) < block_length as usize
128
131
{
129
132
return Err ( error:: Error :: PacketTooShort . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -118,7 +118,10 @@ impl Unmarshal for PacketReceiptTimesReportBlock {
118
118
}
119
119
120
120
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
121
- let block_length = xr_header. block_length * 4 ;
121
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
122
+ Some ( length) => length,
123
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
124
+ } ;
122
125
if block_length < PRT_REPORT_BLOCK_MIN_LENGTH
123
126
|| ( block_length - PRT_REPORT_BLOCK_MIN_LENGTH ) % 4 != 0
124
127
|| raw_packet. remaining ( ) < block_length as usize
Original file line number Diff line number Diff line change @@ -210,7 +210,10 @@ impl Unmarshal for RLEReportBlock {
210
210
}
211
211
212
212
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
213
- let block_length = xr_header. block_length * 4 ;
213
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
214
+ Some ( length) => length,
215
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
216
+ } ;
214
217
if block_length < RLE_REPORT_BLOCK_MIN_LENGTH
215
218
|| ( block_length - RLE_REPORT_BLOCK_MIN_LENGTH ) % 2 != 0
216
219
|| raw_packet. remaining ( ) < block_length as usize
Original file line number Diff line number Diff line change @@ -98,7 +98,10 @@ impl Unmarshal for ReceiverReferenceTimeReportBlock {
98
98
}
99
99
100
100
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
101
- let block_length = xr_header. block_length * 4 ;
101
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
102
+ Some ( length) => length,
103
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
104
+ } ;
102
105
if block_length != RRT_REPORT_BLOCK_LENGTH || raw_packet. remaining ( ) < block_length as usize
103
106
{
104
107
return Err ( error:: Error :: PacketTooShort . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -186,7 +186,10 @@ impl Unmarshal for StatisticsSummaryReportBlock {
186
186
}
187
187
188
188
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
189
- let block_length = xr_header. block_length * 4 ;
189
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
190
+ Some ( length) => length,
191
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
192
+ } ;
190
193
if block_length != SSR_REPORT_BLOCK_LENGTH || raw_packet. remaining ( ) < block_length as usize
191
194
{
192
195
return Err ( error:: Error :: PacketTooShort . into ( ) ) ;
Original file line number Diff line number Diff line change @@ -83,7 +83,10 @@ impl Unmarshal for UnknownReportBlock {
83
83
}
84
84
85
85
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
86
- let block_length = xr_header. block_length * 4 ;
86
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
87
+ Some ( length) => length,
88
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
89
+ } ;
87
90
if raw_packet. remaining ( ) < block_length as usize {
88
91
return Err ( error:: Error :: PacketTooShort . into ( ) ) ;
89
92
}
Original file line number Diff line number Diff line change @@ -149,7 +149,10 @@ impl Unmarshal for VoIPMetricsReportBlock {
149
149
}
150
150
151
151
let xr_header = XRHeader :: unmarshal ( raw_packet) ?;
152
- let block_length = xr_header. block_length * 4 ;
152
+ let block_length = match xr_header. block_length . checked_mul ( 4 ) {
153
+ Some ( length) => length,
154
+ None => return Err ( error:: Error :: InvalidBlockSize . into ( ) ) ,
155
+ } ;
153
156
if block_length != VM_REPORT_BLOCK_LENGTH || raw_packet. remaining ( ) < block_length as usize
154
157
{
155
158
return Err ( error:: Error :: PacketTooShort . into ( ) ) ;
You can’t perform that action at this time.
0 commit comments