Subject: bin/11702: ifconfig is missing a pointer initialization
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mike@pelley.com>
List: netbsd-bugs
Date: 12/11/2000 21:59:18
>Number:         11702
>Category:       bin
>Synopsis:       ifconfig is missing a pointer initialization
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 11 21:59:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Mike Pelley
>Release:        -current from a week or two ago
>Organization:
Foundation

>Environment:
System:
NetBSD trantor.worldmap.net 1.5L NetBSD 1.5L (TRANTOR) #1: Fri Dec 8
00:00:04 EST 2000
mike@trantor.worldmap.net:/usr/src/sys/arch/i386/compile/TRANTOR i386

Architecture: i386
Machine: i386
>Description:
In printall (called from ifconfig -a), sdl is set as so:

	if (ifa->ifa_addr->sa_family == AF_LINK)
		sdl = (const struct sockaddr_dl *) ifa->ifa_addr;

and it's value is checked later:

	if (sdl == NULL) {

It will only be checked without being set if the initial interface
printed fails the first if as sdl is set to NULL after that.

>How-To-Repeat:
Look at code.

>Fix:

Simple patch follows.  /usr/share/misc/style suggests that variables
should not be initialized in the declaration but I copied this from the
else section of the ifdef.  If it is changed they both should be.


Index: ifconfig.c
===================================================================
RCS file: /usr/cvsroot/basesrc/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.91
diff -u -r1.91 ifconfig.c
--- ifconfig.c	2000/11/07 14:47:59	1.91
+++ ifconfig.c	2000/12/12 05:34:54
@@ -691,7 +691,7 @@
 #ifdef HAVE_IFADDRS_H
 	struct ifaddrs *ifap, *ifa;
 	struct ifreq ifr;
-	const struct sockaddr_dl *sdl;
+	const struct sockaddr_dl *sdl = NULL;
 	int idx;
 	char *p;
>Release-Note:
>Audit-Trail:
>Unformatted: