|
276 | 276 | const size_t uxLast = pxNetworkBuffer->xDataLength - uxNeededSize; |
277 | 277 | uint8_t * pucBytes = &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); |
278 | 278 | ICMPPrefixOption_IPv6_t * pxPrefixOption = NULL; |
| 279 | + BaseType_t xMalformed = pdFALSE; |
279 | 280 |
|
280 | 281 | while( ( uxIndex + 1U ) < uxLast ) |
281 | 282 | { |
|
312 | 313 | break; |
313 | 314 |
|
314 | 315 | case ndICMP_PREFIX_INFORMATION: /* 3 */ |
315 | | - /* MISRA Ref 11.3.1 [Misaligned access] */ |
316 | | - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ |
317 | | - /* coverity[misra_c_2012_rule_11_3_violation] */ |
318 | | - pxPrefixOption = ( ( ICMPPrefixOption_IPv6_t * ) &( pucBytes[ uxIndex ] ) ); |
319 | | - |
320 | | - FreeRTOS_printf( ( "RA: Prefix len %d Life %u, %u (%pip)\n", |
321 | | - pxPrefixOption->ucPrefixLength, |
322 | | - ( unsigned ) FreeRTOS_ntohl( pxPrefixOption->ulValidLifeTime ), |
323 | | - ( unsigned ) FreeRTOS_ntohl( pxPrefixOption->ulPreferredLifeTime ), |
324 | | - ( void * ) pxPrefixOption->ucPrefix ) ); |
| 316 | + |
| 317 | + if( uxLength < sizeof( ICMPPrefixOption_IPv6_t ) ) |
| 318 | + { |
| 319 | + FreeRTOS_printf( |
| 320 | + ( "RA: Prefix option too short ( %u < %u )\n", |
| 321 | + ( unsigned ) uxLength, |
| 322 | + ( unsigned ) sizeof( ICMPPrefixOption_IPv6_t ) ) ); |
| 323 | + xMalformed = pdTRUE; |
| 324 | + } |
| 325 | + else |
| 326 | + { |
| 327 | + /* MISRA Ref 11.3.1 [Misaligned access] */ |
| 328 | + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ |
| 329 | + /* coverity[misra_c_2012_rule_11_3_violation] */ |
| 330 | + pxPrefixOption = ( ( ICMPPrefixOption_IPv6_t * ) &( pucBytes[ uxIndex ] ) ); |
| 331 | + |
| 332 | + FreeRTOS_printf( ( "RA: Prefix len %d Life %u, %u (%pip)\n", |
| 333 | + pxPrefixOption->ucPrefixLength, |
| 334 | + ( unsigned ) FreeRTOS_ntohl( pxPrefixOption->ulValidLifeTime ), |
| 335 | + ( unsigned ) FreeRTOS_ntohl( pxPrefixOption->ulPreferredLifeTime ), |
| 336 | + ( void * ) pxPrefixOption->ucPrefix ) ); |
| 337 | + } |
| 338 | + |
325 | 339 | break; |
326 | 340 |
|
327 | 341 | case ndICMP_REDIRECTED_HEADER: /* 4 */ |
|
345 | 359 | break; |
346 | 360 | } |
347 | 361 |
|
| 362 | + if( xMalformed != pdFALSE ) |
| 363 | + { |
| 364 | + FreeRTOS_printf( ( "RA: Malformed packet.\n" ) ); |
| 365 | + break; |
| 366 | + } |
| 367 | + |
348 | 368 | uxIndex = uxIndex + uxLength; |
349 | 369 | } /* while( ( uxIndex + 1 ) < uxLast ) */ |
350 | 370 |
|
|
0 commit comments