facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.79k stars 2k forks source link

Is this feedback correct? #1833

Closed wbhqmzl closed 2 months ago

wbhqmzl commented 2 months ago

define MAX_LEN (16)

void test(const unsigned char *additional, size_t len, size_t nonce_len, size_t entropy_len) {         unsigned char seed[MAX_LEN];         size_t        seedlen = 0;           if(entropy_len > MAX_LEN)              return;         if(nonce_len > MAX_LEN - entropy_len)              return;         if(len > MAX_LEN - entropy_len - nonce_len)              return;           seedlen +=  entropy_len;         if(nonce_len != 0)                 seedlen += nonce_len;         if(additional != NULL && len != 0){                 memcpy(seed + seedlen, additional, len);                 seedlen += len;         } } int main() {         unsigned char arr[20] = {0};         test(arr, 8, 0, 5);         return 0; } Infer:31: error: Buffer Overrun L2 Offset added: [13, 24] (⇐ [5, 16] + 8) Size: 16 by call to test.

  1. {
  2. unsigned char arr[20] = {0};
  3. test(arr, 8, 0, 5); ^
  4. return 0;
  5. } A call to the main function may not cause the array of the called function to go out of bounds