Veracode reported:
This call to
ReadFile()contains a potential buffer overflow. The specified size of 92 bytes is larger than the space allocated to the destination buffer (88 bytes).
The code:
typedef struct
{
char myArray[82];
int number1;
int number2;
} MY_STRUCT;
void test_ExpectBufferOverflow(HANDLE handle)
{
DWORD nRead;
MY_STRUCT my_struct;
ReadFile(handle, &my_struct, sizeof(MY_STRUCT), &nRead, NULL);
}
This is 32-bit Windows code, compiler: MSVC14_X86.
I do not see how buffer overflow can happen here.
How should I fix this?
myArray[82](ormyArray[83]) if these are padding bytes. The membernumber1is probably aligned to 4 bytes, ie at&myArray[84]. See C23 6.2.6.1p6sizeof(int)is 4, the size of the structure should be at least 90 bytes.sizeof(MY_STRUCT)andsizeof my_structreport?