]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use (or define) a macro for the real size of PACKET_OID_DATA
authorDaniel Miller <[email protected]>
Thu, 23 Jan 2025 22:54:20 +0000 (16:54 -0600)
committerGuy Harris <[email protected]>
Fri, 21 Feb 2025 02:51:59 +0000 (18:51 -0800)
pcap-npf.c

index a788036aad29defba30798c3f833c057e5ba7591..7054062a297c28b1b11f6cf707bac55097ceed95 100644 (file)
@@ -185,6 +185,10 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
 #define NDIS_STATUS_NOT_SUPPORTED      0xc00000bb      /* STATUS_NOT_SUPPORTED */
 #define NDIS_STATUS_NOT_RECOGNIZED     0x00010001
 
+#ifndef PACKET_OID_DATA_LENGTH
+#define PACKET_OID_DATA_LENGTH(_DataLength) \
+       (offsetof(PACKET_OID_DATA, Data) + _DataLength)
+#endif
 static int
 oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
     char *errbuf)
@@ -193,12 +197,9 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
 
        /*
         * Allocate a PACKET_OID_DATA structure to hand to PacketRequest().
-        * It should be big enough to hold "*lenp" bytes of data; it
-        * will actually be slightly larger, as PACKET_OID_DATA has a
-        * 1-byte data array at the end, standing in for the variable-length
-        * data that's actually there.
+        * It should be big enough to hold "*lenp" bytes of data;
         */
-       oid_data_arg = malloc(sizeof (PACKET_OID_DATA) + *lenp);
+       oid_data_arg = malloc(PACKET_OID_DATA_LENGTH(*lenp));
        if (oid_data_arg == NULL) {
                snprintf(errbuf, PCAP_ERRBUF_SIZE,
                    "Couldn't allocate argument buffer for PacketRequest");
@@ -393,12 +394,9 @@ pcap_oid_set_request_npf(pcap_t *p, bpf_u_int32 oid, const void *data,
 
        /*
         * Allocate a PACKET_OID_DATA structure to hand to PacketRequest().
-        * It should be big enough to hold "*lenp" bytes of data; it
-        * will actually be slightly larger, as PACKET_OID_DATA has a
-        * 1-byte data array at the end, standing in for the variable-length
-        * data that's actually there.
+        * It should be big enough to hold "*lenp" bytes of data;
         */
-       oid_data_arg = malloc(sizeof (PACKET_OID_DATA) + *lenp);
+       oid_data_arg = malloc(PACKET_OID_DATA_LENGTH(*lenp));
        if (oid_data_arg == NULL) {
                snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
                    "Couldn't allocate argument buffer for PacketRequest");