aboutsummaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-05-09 12:58:33 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-05-09 12:58:33 +0000
commit56f76a10c6fd5c1a2b23760aca22f8ec4b7813da (patch)
tree63c66a57c123c3ae339094aea00387390027f980 /sbin/ifconfig
parent2a0e2c88db208aa24acba56eda07cbb52411bcc1 (diff)
downloadsrc-56f76a10c6fd5c1a2b23760aca22f8ec4b7813da.tar.gz
src-56f76a10c6fd5c1a2b23760aca22f8ec4b7813da.zip
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.
Notes
Notes: svn path=/head/; revision=347392
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 1c46247b36a7..6a42e3a6bb77 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -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[] = {