From owner-freebsd-ports-bugs@FreeBSD.ORG Wed Sep 22 13:30:02 2010 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B84E81065672 for ; Wed, 22 Sep 2010 13:30:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 79EC18FC21 for ; Wed, 22 Sep 2010 13:30:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o8MDU2cg028140 for ; Wed, 22 Sep 2010 13:30:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o8MDU2DX028139; Wed, 22 Sep 2010 13:30:02 GMT (envelope-from gnats) Resent-Date: Wed, 22 Sep 2010 13:30:02 GMT Resent-Message-Id: <201009221330.o8MDU2DX028139@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Lucius Windschuh Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0CB410656A4 for ; Wed, 22 Sep 2010 13:23:08 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 840678FC23 for ; Wed, 22 Sep 2010 13:23:08 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o8MDN8I2052302 for ; Wed, 22 Sep 2010 13:23:08 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id o8MDN87V052289; Wed, 22 Sep 2010 13:23:08 GMT (envelope-from nobody) Message-Id: <201009221323.o8MDN87V052289@www.freebsd.org> Date: Wed, 22 Sep 2010 13:23:08 GMT From: Lucius Windschuh To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/150860: [libpcap] Correctly support FreeBSD 9's interface descriptions X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Sep 2010 13:30:02 -0000 >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: