Fix the module name matching to the drivers present in the kernel. Previously
it would return true on a partial match where it would think the edsc module was already present by having a positive match on 'ed'. This changes it so that it compares the full string including the nul terminators. This also fixes a buffer overflow in the ifkind variable where the length of the interface name in *argv wasnt checked for size. Reviewed by: brooks Approved by: re (gnn)
This commit is contained in:
parent
7924093f84
commit
265e8a9acc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=172438
@ -895,21 +895,28 @@ printb(const char *s, unsigned v, const char *bits)
|
|||||||
void
|
void
|
||||||
ifmaybeload(const char *name)
|
ifmaybeload(const char *name)
|
||||||
{
|
{
|
||||||
|
#define MOD_PREFIX_LEN 3 /* "if_" */
|
||||||
struct module_stat mstat;
|
struct module_stat mstat;
|
||||||
int fileid, modid;
|
int fileid, modid;
|
||||||
char ifkind[35], *dp;
|
char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
|
|
||||||
/* loading suppressed by the user */
|
/* loading suppressed by the user */
|
||||||
if (noload)
|
if (noload)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* trim the interface number off the end */
|
||||||
|
strlcpy(ifname, name, sizeof(ifname));
|
||||||
|
for (dp = ifname; *dp != 0; dp++)
|
||||||
|
if (isdigit(*dp)) {
|
||||||
|
*dp = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* turn interface and unit into module name */
|
/* turn interface and unit into module name */
|
||||||
strcpy(ifkind, "if_");
|
strcpy(ifkind, "if_");
|
||||||
for (cp = name, dp = ifkind + 3;
|
strlcpy(ifkind + MOD_PREFIX_LEN, ifname,
|
||||||
(*cp != 0) && !isdigit(*cp); cp++, dp++)
|
sizeof(ifkind) - MOD_PREFIX_LEN);
|
||||||
*dp = *cp;
|
|
||||||
*dp = 0;
|
|
||||||
|
|
||||||
/* scan files in kernel */
|
/* scan files in kernel */
|
||||||
mstat.version = sizeof(struct module_stat);
|
mstat.version = sizeof(struct module_stat);
|
||||||
@ -926,8 +933,8 @@ ifmaybeload(const char *name)
|
|||||||
cp = mstat.name;
|
cp = mstat.name;
|
||||||
}
|
}
|
||||||
/* already loaded? */
|
/* already loaded? */
|
||||||
if (strncmp(name, cp, strlen(cp)) == 0 ||
|
if (strncmp(ifname, cp, strlen(ifname) + 1) == 0 ||
|
||||||
strncmp(ifkind, cp, strlen(cp)) == 0)
|
strncmp(ifkind, cp, strlen(ifkind) + 1) == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user