summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-09-01 19:20:43 -0700
committerGuy Harris <guy@alum.mit.edu>2015-09-02 18:27:05 -0700
commit95bf0d53f0eb16afd674cd6c340b0620441f830d (patch)
treef322ddd7ce338b3aca336bcdb05cc0c73e9e1cd6
parent80bbc303479005d7bad419120e611a0fe68fa071 (diff)
downloadlibpcap-95bf0d53f0eb16afd674cd6c340b0620441f830d.tar.gz
Don't write past the end of an old pcap_stat structure in pcap_stats().
We might be called from a program compiled with an older version of WinPcap in which the structure doesn't have a ps_capt member, in which case filling that member in will overwrite whatever is after that structure, so don't do that. Don't worry about the packet count we maintain - pcap_stats() ignored it, just returning whatever PacketGetStats() returned, and pcap_stats_ex() overwrote it with whatever PacketGetStatsEx(). Fix a parenthesis error while we're at it.
-rw-r--r--pcap-win32.c47
1 files changed, 12 insertions, 35 deletions
diff --git a/pcap-win32.c b/pcap-win32.c
index 12f71168..347eb4f4 100644
--- a/pcap-win32.c
+++ b/pcap-win32.c
@@ -144,50 +144,25 @@ pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
struct bpf_stat bstats;
/*
- * Copy over any statistics we've had to maintain ourselves,
- * such as captured packet counts on DAG devices.
- */
- *ps = pw->stat;
-
- /*
- * Try to get statistics from the driver.
+ * Try to get statistics.
+ *
* (Please note - "struct pcap_stat" is *not* the same as
* WinPcap's "struct bpf_stat". It might currently have the
- * same layout, but let's not cheat.)
+ * same layout, but let's not cheat.
*
- * Don't assume that PacketGetStats() will fill in all fields.
- * It doesn't fill in bs_capt for NDIS devices, for example;
- * only PacketGetStatsEx() does that, but PacketGetStatsEx()
- * doesn't handle some device types that PacketGetStats() does.
- * This is a mess and needs to be cleaned up.
+ * Note also that we don't fill in ps_capt, as we might have
+ * been called by code compiled against an earlier version of
+ * WinPcap that didn't have ps_capt, in which case filling it
+ * in would stomp on whatever comes after the structure passed
+ * to us.
*/
- bstats.bs_recv = 0;
- bstats.bs_drop = 0;
- bstats.bs_ifdrop = 0;
- bstats.bs_capt = 0;
- if (!PacketGetStats(p->adapter, &bstats) {
+ if (!PacketGetStats(p->adapter, &bstats)) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "PacketGetStats error: %s", pcap_win32strerror());
return -1;
}
- if (bstats.bs_recv != 0) {
- /*
- * If it's zero, that might mean that the captured packet
- * count isn't maintained, so use our value.
- *
- * XXX - either Packet.dll should be maintaining the count
- * and hiding this dependency from us, or Packet.dll
- * shouldn't be handling DAG cards *at all*, they should
- * be handled directly by us, with code that runs on top of
- * the DAG API on windows (i.e., move Packet.dll's DAG
- * card code into pcap, given that we now have our own
- * mechanism for handling different adapter types with
- * different code).
- */
- ps->ps_recv = bstats.bs_recv;
- }
+ ps->ps_recv = bstats.bs_recv;
ps->ps_drop = bstats.bs_drop;
ps->ps_ifdrop = bstats.ps_ifdrop;
- ps->ps_capt = bstats.bs_capt;
return 0;
}
@@ -230,6 +205,8 @@ pcap_stats_ex(pcap_t *p, int *pcap_stat_size)
#endif
/*
+ * Try to get statistics.
+ *
* (Please note - "struct pcap_stat" is *not* the same as
* WinPcap's "struct bpf_stat". It might currently have the
* same layout, but let's not cheat.)