Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 May 2017 22:45:01 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r319265 - stable/10/sbin/ifconfig
Message-ID:  <201705302245.v4UMj1CB075853@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Tue May 30 22:45:01 2017
New Revision: 319265
URL: https://svnweb.freebsd.org/changeset/base/319265

Log:
  MFC r317755, r317758
  
  r317755:
  Various Coverity fixes in ifconfig(8)
  
  * Exit early if kldload(2) fails (1011259). This is the only change that
    affects ifconfig's behavior.
  * Close memory and resource leaks (1305624, 1305205, 1007100)
  * Mark usage() as _Noreturn (1305806, 1305750)
  * Fix some dereference after null checks (1011474, 270774)
  
  Reported by:	Coverity
  CID:		1305624, 1305205, 1007100, 1305806, 1305750, 1011474,
  CID:		270774, 1011259
  Reviewed by:	cem
  Sponsored by:	Spectra Logic Corp
  Differential Revision:	https://reviews.freebsd.org/D10587
  
  r317758:
  Unbreak ifconfig for mlx4en(4) after r317755
  
  ifconfig doesn't correctly infer mlx interfaces' module names, so it will
  attempt to load the mlx(4) module even when not necessary.
  
  Reported by:	rstone
  X-MFC-With:	317755
  Sponsored by:	Spectra Logic Corp

Modified:
  stable/10/sbin/ifconfig/af_inet6.c
  stable/10/sbin/ifconfig/ifclone.c
  stable/10/sbin/ifconfig/ifconfig.c
  stable/10/sbin/ifconfig/iflagg.c
  stable/10/sbin/ifconfig/ifpfsync.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/ifconfig/af_inet6.c
==============================================================================
--- stable/10/sbin/ifconfig/af_inet6.c	Tue May 30 22:44:05 2017	(r319264)
+++ stable/10/sbin/ifconfig/af_inet6.c	Tue May 30 22:45:01 2017	(r319265)
@@ -336,12 +336,14 @@ in6_getaddr(const char *s, int which)
 		bzero(&hints, sizeof(struct addrinfo));
 		hints.ai_family = AF_INET6;
 		error = getaddrinfo(s, NULL, &hints, &res);
+		if (error != 0) {
+			if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
+				errx(1, "%s: bad value", s);
+		} else {
+			bcopy(res->ai_addr, sin, res->ai_addrlen);
+			freeaddrinfo(res);
+		}
 	}
-	if (error != 0) {
-		if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
-			errx(1, "%s: bad value", s);
-	} else
-		bcopy(res->ai_addr, sin, res->ai_addrlen);
 }
 
 static int

Modified: stable/10/sbin/ifconfig/ifclone.c
==============================================================================
--- stable/10/sbin/ifconfig/ifclone.c	Tue May 30 22:44:05 2017	(r319264)
+++ stable/10/sbin/ifconfig/ifclone.c	Tue May 30 22:45:01 2017	(r319265)
@@ -87,6 +87,7 @@ list_cloners(void)
 
 	putchar('\n');
 	free(buf);
+	close(s);
 }
 
 struct clone_defcb {

Modified: stable/10/sbin/ifconfig/ifconfig.c
==============================================================================
--- stable/10/sbin/ifconfig/ifconfig.c	Tue May 30 22:44:05 2017	(r319264)
+++ stable/10/sbin/ifconfig/ifconfig.c	Tue May 30 22:45:01 2017	(r319265)
@@ -103,7 +103,7 @@ static	int ifconfig(int argc, char *const *argv, int i
 static	void status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
 		struct ifaddrs *ifa);
 static	void tunnel_status(int s);
-static	void usage(void);
+static	void usage(void) _Noreturn;
 
 static struct afswtch *af_getbyname(const char *name);
 static struct afswtch *af_getbyfamily(int af);
@@ -577,26 +577,24 @@ top:
 			 */
 			p = (setaddr ? &setifdstaddr_cmd : &setifaddr_cmd);
 		}
-		if (p->c_u.c_func || p->c_u.c_func2) {
-			if (p->c_parameter == NEXTARG) {
-				if (argv[1] == NULL)
-					errx(1, "'%s' requires argument",
-					    p->c_name);
-				p->c_u.c_func(argv[1], 0, s, afp);
+		if (p->c_parameter == NEXTARG && p->c_u.c_func) {
+			if (argv[1] == NULL)
+				errx(1, "'%s' requires argument",
+				    p->c_name);
+			p->c_u.c_func(argv[1], 0, s, afp);
+			argc--, argv++;
+		} else if (p->c_parameter == OPTARG && p->c_u.c_func) {
+			p->c_u.c_func(argv[1], 0, s, afp);
+			if (argv[1] != NULL)
 				argc--, argv++;
-			} else if (p->c_parameter == OPTARG) {
-				p->c_u.c_func(argv[1], 0, s, afp);
-				if (argv[1] != NULL)
-					argc--, argv++;
-			} else if (p->c_parameter == NEXTARG2) {
-				if (argc < 3)
-					errx(1, "'%s' requires 2 arguments",
-					    p->c_name);
-				p->c_u.c_func2(argv[1], argv[2], s, afp);
-				argc -= 2, argv += 2;
-			} else
-				p->c_u.c_func(*argv, p->c_parameter, s, afp);
-		}
+		} else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) {
+			if (argc < 3)
+				errx(1, "'%s' requires 2 arguments",
+				    p->c_name);
+			p->c_u.c_func2(argv[1], argv[2], s, afp);
+			argc -= 2, argv += 2;
+		} else if (p->c_u.c_func)
+			p->c_u.c_func(*argv, p->c_parameter, s, afp);
 		argc--, argv++;
 	}
 
@@ -1086,8 +1084,8 @@ printb(const char *s, unsigned v, const char *bits)
 		printf("%s=%o", s, v);
 	else
 		printf("%s=%x", s, v);
-	bits++;
 	if (bits) {
+		bits++;
 		putchar('<');
 		while ((i = *bits++) != '\0') {
 			if (v & (1 << (i-1))) {
@@ -1165,8 +1163,11 @@ ifmaybeload(const char *name)
 		}
 	}
 
-	/* not present, we should try to load it */
-	kldload(ifkind);
+	/*
+	 * Try to load the module.  But ignore failures, because ifconfig can't
+	 * infer the names of all drivers (eg mlx4en(4)).
+	 */
+	(void) kldload(ifkind);
 }
 
 static struct cmd basic_cmds[] = {

Modified: stable/10/sbin/ifconfig/iflagg.c
==============================================================================
--- stable/10/sbin/ifconfig/iflagg.c	Tue May 30 22:44:05 2017	(r319264)
+++ stable/10/sbin/ifconfig/iflagg.c	Tue May 30 22:45:01 2017	(r319265)
@@ -187,24 +187,17 @@ static void
 lagg_status(int s)
 {
 	struct lagg_protos lpr[] = LAGG_PROTOS;
-	struct lagg_reqport rp, rpbuf[LAGG_MAX_PORTS];
+	struct lagg_reqport rpbuf[LAGG_MAX_PORTS];
 	struct lagg_reqall ra;
 	struct lagg_reqopts ro;
 	struct lagg_reqflags rf;
 	struct lacp_opreq *lp;
 	const char *proto = "<unknown>";
-	int i, isport = 0;
+	int i;
 
-	bzero(&rp, sizeof(rp));
 	bzero(&ra, sizeof(ra));
 	bzero(&ro, sizeof(ro));
 
-	strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname));
-	strlcpy(rp.rp_portname, name, sizeof(rp.rp_portname));
-
-	if (ioctl(s, SIOCGLAGGPORT, &rp) == 0)
-		isport = 1;
-
 	strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname));
 	ra.ra_size = sizeof(rpbuf);
 	ra.ra_port = rpbuf;
@@ -244,8 +237,6 @@ lagg_status(int s)
 				sep = ",";
 			}
 		}
-		if (isport)
-			printf(" laggdev %s", rp.rp_ifname);
 		putchar('\n');
 		if (verbose) {
 			printf("\tlagg options:\n");

Modified: stable/10/sbin/ifconfig/ifpfsync.c
==============================================================================
--- stable/10/sbin/ifconfig/ifpfsync.c	Tue May 30 22:44:05 2017	(r319264)
+++ stable/10/sbin/ifconfig/ifpfsync.c	Tue May 30 22:45:01 2017	(r319265)
@@ -120,6 +120,7 @@ setpfsync_syncpeer(const char *val, int d, int s, cons
 
 	if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1)
 		err(1, "SIOCSETPFSYNC");
+	freeaddrinfo(peerres);
 }
 
 /* ARGSUSED */



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