Re: [tcpdump-workers] [Patch] fad-win32.c
"Guy Harris" wrote: 'NameLength = 0' is just in case 'PacketGetAdapterNames()' fails w/o setting '*NameLength == 0'. It really could do that; ref. Packet32.c in WinPcap. Really? I don't see that. (The first call should *always* "fail", in the sense of returning FALSE; if the cause of the "failure" is that the buffer pointer argument is NULL, not that it couldn't get the interface list, it should set NameLength to the size of the buffer it needs.) What is the oldest version of WinPcap we should support in libpcap? Here are the lines in question from an old version of \Packet9x\DLL\Packet32.c: BOOLEAN PacketGetAdapterNames (PTSTR pStr, PULONG BufferSize) { ULONG Result,i; LONG Status; ... PPACKET_OID_DATA OidData; ... OidData=GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT,256); if (OidData == NULL) { return FALSE; } (dated 8 July 2006 here). Clearly it could return FALSE w/o touching '*BufferSize'. The GlobalAllocPtr() is the 1st code in this function. Hence the precaution in fad-win32.c. Allthough no sane person should be using Win9x anymore, there could be an old version of PacketNtx\Dll\Packet32.c with the same lines. --gv ___ tcpdump-workers mailing list tcpdump-workers@lists.tcpdump.org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers
Re: [tcpdump-workers] [Patch] fad-win32.c
On Apr 4, 2013, at 1:20 AM, Gisle Vanem wrote: > This is a similar patch to the change of pcap-dos.c: > https://github.com/mcr/libpcap/commit/73b5f0387199fbaa75130837b931faf770471640 > > I.e. the '_interfaces' suffix got lost in some other change to the puplic API. > (I don't know when). Since 'pcap_findalldevs()' is now a more generic version > in pcap.c, the platform-specific function is called > 'pcap_findalldevs_interfaces()' in fad-win32.c: Checked in to the trunk and 1.4 branches. > 'NameLength = 0' is just in case 'PacketGetAdapterNames()' fails > w/o setting '*NameLength == 0'. It really could do that; ref. Packet32.c in > WinPcap. Really? I don't see that. (The first call should *always* "fail", in the sense of returning FALSE; if the cause of the "failure" is that the buffer pointer argument is NULL, not that it couldn't get the interface list, it should set NameLength to the size of the buffer it needs.) However, PacketGetAdapterNames() *will* check whether the buffer size argument is big enough before checking whether the buffer pointer argument is null; if either one is true, it'll "fail" with ERROR_INSUFFICIENT_BUFFER and set NameLength to the required buffer size, but, as long as it tests the buffer size before the buffer pointer, we should, for cleanliness' sake, initialize the buffer size to 0. ___ tcpdump-workers mailing list tcpdump-workers@lists.tcpdump.org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers
[tcpdump-workers] [Patch] fad-win32.c
This is a similar patch to the change of pcap-dos.c: https://github.com/mcr/libpcap/commit/73b5f0387199fbaa75130837b931faf770471640 I.e. the '_interfaces' suffix got lost in some other change to the puplic API. (I don't know when). Since 'pcap_findalldevs()' is now a more generic version in pcap.c, the platform-specific function is called 'pcap_findalldevs_interfaces()' in fad-win32.c: --- Git-Latest\fad-win32.c Wed Nov 28 23:41:44 2012 +++ fad-win32.c Wed Mar 27 16:14:02 2013 @@ -216,13 +216,13 @@ * Win32 implementation, based on WinPcap */ int -pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) +pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf) { pcap_if_t *devlist = NULL; int ret = 0; const char *desc; char *AdaptersName; - ULONG NameLength; + ULONG NameLength = 0; char *name; if (!PacketGetAdapterNames(NULL, &NameLength)) - 'NameLength = 0' is just in case 'PacketGetAdapterNames()' fails w/o setting '*NameLength == 0'. It really could do that; ref. Packet32.c in WinPcap. --gv ___ tcpdump-workers mailing list tcpdump-workers@lists.tcpdump.org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers