From owner-svn-src-head@freebsd.org Thu May 9 12:58:35 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E0DD515A8D6D; Thu, 9 May 2019 12:58:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 84AD48DFFE; Thu, 9 May 2019 12:58:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5CBAC1D4C7; Thu, 9 May 2019 12:58:34 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x49CwYnd095201; Thu, 9 May 2019 12:58:34 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x49CwYr0095200; Thu, 9 May 2019 12:58:34 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201905091258.x49CwYr0095200@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 9 May 2019 12:58:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347392 - head/sbin/ifconfig X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sbin/ifconfig X-SVN-Commit-Revision: 347392 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 84AD48DFFE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 May 2019 12:58:35 -0000 Author: kevans Date: Thu May 9 12:58:33 2019 New Revision: 347392 URL: https://svnweb.freebsd.org/changeset/base/347392 Log: ifconfig(8): Partial revert of r347241 r347241 introduced an ifname <-> kld mapping table, mostly so tun/tap/vmnet can autoload the correct module on use. It also inadvertently made bogus some previously valid uses of sizeof(). Revert back to ifkind on the stack for simplicity sake. This reduces the diff from the previous version of ifmaybeload for easiser auditing. Modified: head/sbin/ifconfig/ifconfig.c Modified: head/sbin/ifconfig/ifconfig.c ============================================================================== --- head/sbin/ifconfig/ifconfig.c Thu May 9 12:14:52 2019 (r347391) +++ head/sbin/ifconfig/ifconfig.c Thu May 9 12:58:33 2019 (r347392) @@ -1433,7 +1433,7 @@ ifmaybeload(const char *name) #define MOD_PREFIX_LEN 3 /* "if_" */ struct module_stat mstat; int i, fileid, modid; - char ifname[IFNAMSIZ], *ifkind, *dp; + char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp; const char *cp; struct module_map_entry *mme; @@ -1450,21 +1450,17 @@ ifmaybeload(const char *name) } /* Either derive it from the map or guess otherwise */ - ifkind = NULL; + *ifkind = '\0'; for (i = 0; i < nitems(module_map); ++i) { mme = &module_map[i]; if (strcmp(mme->ifname, ifname) == 0) { - ifkind = strdup(mme->kldname); - if (ifkind == NULL) - err(EXIT_FAILURE, "ifmaybeload"); + strlcpy(ifkind, mme->kldname, sizeof(ifkind)); break; } } /* We didn't have an alias for it... we'll guess. */ - if (ifkind == NULL) { - ifkind = malloc(IFNAMSIZ + MOD_PREFIX_LEN); - + if (*ifkind == '\0') { /* turn interface and unit into module name */ strlcpy(ifkind, "if_", sizeof(ifkind)); strlcat(ifkind, ifname, sizeof(ifkind)); @@ -1487,7 +1483,7 @@ ifmaybeload(const char *name) /* already loaded? */ if (strcmp(ifname, cp) == 0 || strcmp(ifkind, cp) == 0) - goto out; + return; } } @@ -1496,8 +1492,6 @@ ifmaybeload(const char *name) * infer the names of all drivers (eg mlx4en(4)). */ (void) kldload(ifkind); -out: - free(ifkind); } static struct cmd basic_cmds[] = {