Skip to content

Commit bca0896

Browse files
committed
wpa: fix a case where freq translation could be garbage
1 parent ab978c0 commit bca0896

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/libdhcpcd/wpa.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,19 @@ dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *wis)
255255
}
256256
}
257257

258-
static void
258+
static int
259259
dhcpcd_strtoi(int *val, const char *s)
260260
{
261261
long l;
262262

263263
l = strtol(s, NULL, 0);
264-
if (l >= INT_MIN && l <= INT_MAX)
265-
*val = (int)l;
266-
else
264+
if (l < INT_MIN || l > INT_MAX) {
267265
errno = ERANGE;
266+
return -1;
267+
}
268+
269+
*val = (int)l;
270+
return 0;
268271
}
269272

270273
static int
@@ -1303,7 +1306,8 @@ dhcpcd_wpa_freq(DHCPCD_WPA *wpa)
13031306
if (*s == '\0')
13041307
continue;
13051308
if (strncmp(s, "freq=", 5) == 0) {
1306-
dhcpcd_strtoi(&freq, s + 5);
1309+
if (dhcpcd_strtoi(&freq, s + 5) == -1)
1310+
return 0;
13071311
return freq;
13081312
}
13091313
}

0 commit comments

Comments
 (0)