Date: Thu, 9 May 2019 12:58:34 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347392 - head/sbin/ifconfig Message-ID: <201905091258.x49CwYr0095200@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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[] = {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905091258.x49CwYr0095200>