intel / intel-ipsec-mb

Intel(R) Multi-Buffer Crypto for IPSec
BSD 3-Clause "New" or "Revised" License
292 stars 88 forks source link

potential null pointer dereference if malloc fails. #81

Closed ColinIanKing closed 3 years ago

ColinIanKing commented 3 years ago

OK, malloc never normally fails especially in test frameworks, but it can, so it's probably a good idea to add a malloc null pointer failure check.

In test/snow_v_test.c we have,

 904 static uint32_t check_buffer_over_under_write(uint8_t *result,
 905                        const int pad_pattern,
 906                        size_t pad_size,
 907                        size_t alloc_size)
 908 {
    1. returned_null: malloc returns NULL.
    2. var_assigned: Assigning: pad_block = NULL return value from malloc.
 909        uint8_t *pad_block = malloc(pad_size);
 910        uint8_t error = 0;
 911        /* check for buffer under/over-write */
    CID 113777 (#1 of 1): Dereference null return value (NULL_RETURNS)
    3. dereference: Dereferencing a pointer that might be NULL pad_block when calling memset.
 912        memset(pad_block, pad_pattern, pad_size);