Prevent potential integer overflow when computing PACKET_OID_DATA allocation size#1647
Conversation
…llocation size for PACKET_OID_DATA buffers used in Windows NPF OID request handlers. Both oid_get_request() and pcap_oid_set_request_npf() allocate memory using a size derived from: offsetof(PACKET_OID_DATA, Data) + *lenp If *lenp is extremely large, this addition may overflow size_t, causing a small allocation while subsequent operations assume a larger buffer. This can lead to heap memory corruption when the driver writes OID response data into the buffer. The patch introduces explicit overflow checks before computing the allocation size and uses a safe allocation pattern.
|
Please clean this up completely and explain why this is not a vulnerability. |
|
Thank you for the review. You are correct that this should not be considered a vulnerability. The The change simply adds a defensive check before computing the allocation size:
If I will clean up the patch and description to present this purely as a defensive improvement to the allocation size calculation rather than a security vulnerability. |
This change adds a defensive check when computing the allocation size for PACKET_OID_DATA structures used in Windows NPF OID request handling.
The allocation size is computed using:
offsetof(PACKET_OID_DATA, Data) + *lenp
If *lenp were extremely large, the addition could overflow size_t, which could cause malloc() to allocate a buffer smaller than intended.
In practice, lenp is provided by the calling application through the public API and is not derived from external input, so this should not be considered a vulnerability. However, adding an explicit check prevents the arithmetic from overflowing and makes the allocation logic more robust.