Fix missing error checks for strtoul(3)

This commit is contained in:
Xavier Del Campo Romero 2023-04-30 22:12:57 +02:00
parent cfd0a6f774
commit 401c5dcf44
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
2 changed files with 13 additions and 4 deletions

10
http.c
View File

@ -1897,9 +1897,17 @@ char *http_decode_url(const char *url)
else if (*(url + 1) && *(url + 2))
{
const char buf[sizeof "00"] = {*(url + 1), *(url + 2)};
char *endptr;
const unsigned long res = strtoul(buf, &endptr, 16);
if (*endptr)
{
fprintf(stderr, "%s: invalid number %s\n", __func__, buf);
goto failure;
}
ret[n++] = strtoul(buf, NULL, 16);
url += 3;
ret[n++] = res;
}
else
{

7
main.c
View File

@ -1107,11 +1107,12 @@ static int parse_args(const int argc, char *const argv[],
case 'p':
{
const unsigned long portul = strtoul(optarg, NULL, 10);
char *endptr;
const unsigned long portul = strtoul(optarg, &endptr, 10);
if (portul > UINT16_MAX)
if (*endptr || portul > UINT16_MAX)
{
fprintf(stderr, "%s: invalid port %lu\n", __func__, portul);
fprintf(stderr, "%s: invalid port %s\n", __func__, optarg);
return -1;
}