Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Sep 2010 13:23:08 GMT
From:      Lucius Windschuh <lwindschuh@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/150860: [libpcap] Correctly support FreeBSD 9's interface descriptions
Message-ID:  <201009221323.o8MDN87V052289@www.freebsd.org>
Resent-Message-ID: <201009221330.o8MDU2DX028139@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         150860
>Category:       ports
>Synopsis:       [libpcap] Correctly support FreeBSD 9's interface descriptions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 22 13:30:02 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Lucius Windschuh
>Release:        9.0-CURRENT r211737
>Organization:
>Environment:
FreeBSD t400 9.0-CURRENT FreeBSD 9.0-CURRENT #3 r211737MP: Tue Aug 24 12:15:40 CEST 2010     root@t400:/usr/obj/usr/src/sys/CURRENT  i386
>Description:
Wireshark (and also libpcap's findalldevstest test program, to quickly test it), print out garbage as interface description, as the content of uninitialized memory is copied into the description string if no interface description (e.g. ifconfig wlan0 description "this is a slow interface") is available.
This behaviour is only observed if malloc(3) debugging is enabled, e.g. with MALLOC_OPTIONS=AJ 
The attached patch brings our port's libpcap-1.1.1 description handling to the state of the libpcap git master branch, giving now the correct description or indicating that none is available:

/tmp/libpcap-1.1.1-patched# env MALLOC_OPTIONS=AJ ./findalldevstest
em0
        Loopback: no
        Address Family: Unknown (18)

ue0
        Loopback: no
        Address Family: Unknown (18)

wlan0
        Description: this is a slow interface
        Loopback: no
        Address Family: Unknown (18)
/tmp/libpcap-1.1.1-patched$

Please put the attached patch into net/libpcap/files/, until a newer version is released.
This bug also exists on 8.1-STABLE and is also fixed by the attached patch, i tested it.
>How-To-Repeat:
Run "env MALLOC_OPTIONS=AJ wireshark -D", compiled with libpcap from the ports tree, see garbled characters as interface description after the interface name, if no description was set.
>Fix:
Use the attached patch

Patch attached with submission follows:

--- inet.c 
+++ inet.c 
@@ -431,26 +431,36 @@
 	strlcpy(ifrdesc.ifr_name, name, sizeof ifrdesc.ifr_name);
 	s = socket(AF_INET, SOCK_DGRAM, 0);
 	if (s >= 0) {
+#ifdef __FreeBSD__
+		/*
+		 * On FreeBSD, if the buffer isn't big enough for the
+		 * description, the ioctl succeeds, but the description
+		 * isn't copied, ifr_buffer.length is set to the description
+		 * length, and ifr_buffer.buffer is set to NULL.
+		 */
 		for (;;) {
 			free(description);
 			if ((description = malloc(descrlen)) != NULL) {
-#ifdef __FreeBSD__
 				ifrdesc.ifr_buffer.buffer = description;
 				ifrdesc.ifr_buffer.length = descrlen;
-#else /* __FreeBSD__ */
-				ifrdesc.ifr_data = (caddr_t)description;
-#endif /* __FreeBSD__ */
-				if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0)
+				if (ioctl(s, SIOCGIFDESCR, &ifrdesc) == 0) {
+					if (ifrdesc.ifr_buffer.buffer ==
+					    description)
+						break;
+					else
+						descrlen = ifrdesc.ifr_buffer.length;
+				} else {
+					/*
+					 * Failed to get interface description.
+					 */
+					free(description);
+					description = NULL;
 					break;
-#ifdef __FreeBSD__
-				else if (errno == ENAMETOOLONG)
-					descrlen = ifrdesc.ifr_buffer.length;
-#endif /* __FreeBSD__ */
-				else
-					break;
+				}
 			} else
 				break;
 		}
+#endif /* __FreeBSD__ */
 		close(s);
 		if (description != NULL && strlen(description) == 0) {
 			free(description);


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201009221323.o8MDN87V052289>