From 8276e3a1ad8f3ddb73e6785ed1cd10c9e89b7692 Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 9 Apr 2015 21:06:51 +0000 Subject: [PATCH] MFC 279951: Simplify string mangling in ifmaybeload(). - Use strlcpy() instead of strcpy(). - Use strlcat() instead of a strlcpy() with a magic number subtracted from the length. - Replace strncmp(..., strlen(foo) + 1) with strcmp(...). git-svn-id: svn://svn.freebsd.org/base/stable/10@281326 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sbin/ifconfig/ifconfig.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 6d29f20e4..dafb0f09a 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1121,9 +1121,8 @@ ifmaybeload(const char *name) } /* turn interface and unit into module name */ - strcpy(ifkind, "if_"); - strlcpy(ifkind + MOD_PREFIX_LEN, ifname, - sizeof(ifkind) - MOD_PREFIX_LEN); + strlcpy(ifkind, "if_", sizeof(ifkind)); + strlcat(ifkind, ifname, sizeof(ifkind)); /* scan files in kernel */ mstat.version = sizeof(struct module_stat); @@ -1140,8 +1139,8 @@ ifmaybeload(const char *name) cp = mstat.name; } /* already loaded? */ - if (strncmp(ifname, cp, strlen(ifname) + 1) == 0 || - strncmp(ifkind, cp, strlen(ifkind) + 1) == 0) + if (strcmp(ifname, cp) == 0 || + strcmp(ifkind, cp) == 0) return; } } -- 2.45.0