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(...).

Differential Revision:	https://reviews.freebsd.org/D1814
Reviewed by:	rpaulo
MFC after:	2 weeks
This commit is contained in:
John Baldwin 2015-03-13 09:45:06 +00:00
parent 02cbfd02ba
commit 07bf9879f3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279951

View File

@ -1280,9 +1280,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);
@ -1299,8 +1298,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;
}
}