Skip to content

Commit bc02377

Browse files
bonsaivikingguyharris
authored andcommitted
Use (or define) a macro for the real size of PACKET_OID_DATA
1 parent bc10764 commit bc02377

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

pcap-npf.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
185185
#define NDIS_STATUS_NOT_SUPPORTED 0xc00000bb /* STATUS_NOT_SUPPORTED */
186186
#define NDIS_STATUS_NOT_RECOGNIZED 0x00010001
187187

188+
#ifndef PACKET_OID_DATA_LENGTH
189+
#define PACKET_OID_DATA_LENGTH(_DataLength) \
190+
(offsetof(PACKET_OID_DATA, Data) + _DataLength)
191+
#endif
188192
static int
189193
oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
190194
char *errbuf)
@@ -193,12 +197,9 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
193197

194198
/*
195199
* Allocate a PACKET_OID_DATA structure to hand to PacketRequest().
196-
* It should be big enough to hold "*lenp" bytes of data; it
197-
* will actually be slightly larger, as PACKET_OID_DATA has a
198-
* 1-byte data array at the end, standing in for the variable-length
199-
* data that's actually there.
200+
* It should be big enough to hold "*lenp" bytes of data;
200201
*/
201-
oid_data_arg = malloc(sizeof (PACKET_OID_DATA) + *lenp);
202+
oid_data_arg = malloc(PACKET_OID_DATA_LENGTH(*lenp));
202203
if (oid_data_arg == NULL) {
203204
snprintf(errbuf, PCAP_ERRBUF_SIZE,
204205
"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,
393394

394395
/*
395396
* Allocate a PACKET_OID_DATA structure to hand to PacketRequest().
396-
* It should be big enough to hold "*lenp" bytes of data; it
397-
* will actually be slightly larger, as PACKET_OID_DATA has a
398-
* 1-byte data array at the end, standing in for the variable-length
399-
* data that's actually there.
397+
* It should be big enough to hold "*lenp" bytes of data;
400398
*/
401-
oid_data_arg = malloc(sizeof (PACKET_OID_DATA) + *lenp);
399+
oid_data_arg = malloc(PACKET_OID_DATA_LENGTH(*lenp));
402400
if (oid_data_arg == NULL) {
403401
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
404402
"Couldn't allocate argument buffer for PacketRequest");

0 commit comments

Comments
 (0)