Validate the enterprise ID in the DHCPv6 vendor-class parser.

Use atoi_check()to ensure that the enterprise-ID is a valid decimal number.

Inspired by a patch from  DL6ER <dl6er@dl6er.de>
This commit is contained in:
Simon Kelley committed 2026-08-17 12:53:51 +01:00
1 parent 4388c38468
commit 0c177ad607
1 file changed
+13 -13
+13 -13
View File
@@ -745,7 +745,7 @@ static int numeric_check(char *a)
{
char *p;
if (!a)
if (!a || *a == 0)
return 0;
unhide_metas(a);
@@ -771,11 +771,14 @@ static int strtoul_check(char *a, u32 *res)
if (!numeric_check(a))
return 0;
x = strtoul(a, NULL, 10);
if (errno || x > UINT32_MAX) {
errno = 0;
return 0;
}
if (errno || x > UINT32_MAX)
{
errno = 0;
return 0;
}
*res = (u32)x;
return 1;
}
@@ -1896,7 +1899,7 @@ static int parse_dhcp_opt(char *errstr, char *arg, int flags)
{
/* First arg is Enterprise ID (4 bytes)
subsequent are length fields (2 bytes each) + string */
int i, commas = 1;
int enterprise, i, commas = 1;
unsigned char *p, *newp;
for (i = 0; comma[i]; i++)
@@ -1908,14 +1911,11 @@ static int parse_dhcp_opt(char *errstr, char *arg, int flags)
arg = comma;
comma = split(arg);
if (arg && *arg)
{
unsigned int enterprise = atoi(arg);
PUTLONG(enterprise, p);
}
if (atoi_check(arg, &enterprise))
PUTLONG(enterprise, p);
else
goto_err(_("missing enterprise ID in dhcp-option"));
goto_err(_("bad or missing enterprise ID in dhcp-option"));
arg = comma;
comma = split(arg);