Pass the base for strtoll() to kore_strtonum(), breakage ensues if we depend on the "auto" detection that happens when we pass 0 to strtoll() as base.

This commit is contained in:
Joris Vink 2013-08-13 16:13:43 +02:00
parent af5f416e6d
commit bbb245654d
4 changed files with 13 additions and 13 deletions

View File

@ -306,7 +306,7 @@ void kore_log(int, const char *, ...);
void kore_strlcpy(char *, const char *, size_t);
void kore_server_disconnect(struct connection *);
int kore_split_string(char *, char *, char **, size_t);
long long kore_strtonum(const char *, long long, long long, int *);
long long kore_strtonum(const char *, int, long long, long long, int *);
int kore_base64_encode(u_int8_t *, u_int32_t, char **);
int kore_base64_decode(char *, u_int8_t **, u_int32_t *);

View File

@ -221,7 +221,7 @@ configure_spdy_idle_time(char **argv)
if (argv[1] == NULL)
return (KORE_RESULT_ERROR);
spdy_idle_time = kore_strtonum(argv[1], 0, 65535, &err);
spdy_idle_time = kore_strtonum(argv[1], 10, 0, 65535, &err);
if (err != KORE_RESULT_OK) {
kore_debug("spdy_idle_time has invalid value: %s", argv[1]);
return (KORE_RESULT_ERROR);
@ -328,7 +328,7 @@ configure_workers(char **argv)
if (argv[1] == NULL)
return (KORE_RESULT_ERROR);
worker_count = kore_strtonum(argv[1], 1, 255, &err);
worker_count = kore_strtonum(argv[1], 10, 1, 255, &err);
if (err != KORE_RESULT_OK) {
kore_debug("%s is not a correct worker number", argv[1]);
return (KORE_RESULT_ERROR);
@ -427,7 +427,7 @@ configure_max_connections(char **argv)
if (argv[1] == NULL)
return (KORE_RESULT_ERROR);
worker_max_connections = kore_strtonum(argv[1], 1, 65535, &err);
worker_max_connections = kore_strtonum(argv[1], 10, 1, 65535, &err);
if (err != KORE_RESULT_OK)
return (KORE_RESULT_ERROR);

View File

@ -403,7 +403,7 @@ http_header_recv(struct netbuf *nb)
return (KORE_RESULT_ERROR);
}
clen = kore_strtonum(p, 0, UINT_MAX, &v);
clen = kore_strtonum(p, 10, 0, UINT_MAX, &v);
if (v == KORE_RESULT_ERROR) {
kore_mem_free(p);
kore_debug("content-length invalid: %s", p);
@ -523,7 +523,7 @@ http_argument_urldecode(char *arg)
h[3] = *(p + 2);
h[4] = '\0';
v = kore_strtonum(h, 32, 127, &err);
v = kore_strtonum(h, 16, 32, 127, &err);
if (err != KORE_RESULT_OK)
return (err);

View File

@ -87,7 +87,7 @@ kore_strlcpy(char *dst, const char *src, size_t len)
}
long long
kore_strtonum(const char *str, long long min, long long max, int *err)
kore_strtonum(const char *str, int base, long long min, long long max, int *err)
{
long long l;
char *ep;
@ -99,7 +99,7 @@ kore_strtonum(const char *str, long long min, long long max, int *err)
l = 0;
errno = 0;
l = strtoll(str, &ep, 0);
l = strtoll(str, &ep, base);
if (errno != 0 || str == ep || *ep != '\0') {
*err = KORE_RESULT_ERROR;
return (0);
@ -157,7 +157,7 @@ kore_date_to_time(char *http_date)
goto out;
}
tm.tm_year = kore_strtonum(args[3], 2013, 2068, &err) - 1900;
tm.tm_year = kore_strtonum(args[3], 10, 2013, 2068, &err) - 1900;
if (err == KORE_RESULT_ERROR || tm.tm_year < gtm->tm_year) {
kore_debug("misformed year in http-date: '%s'", http_date);
goto out;
@ -175,7 +175,7 @@ kore_date_to_time(char *http_date)
goto out;
}
tm.tm_mday = kore_strtonum(args[1], 1, 31, &err);
tm.tm_mday = kore_strtonum(args[1], 10, 1, 31, &err);
if (err == KORE_RESULT_ERROR) {
kore_debug("misformed mday in http-date: '%s'", http_date);
goto out;
@ -186,19 +186,19 @@ kore_date_to_time(char *http_date)
goto out;
}
tm.tm_hour = kore_strtonum(tbuf[0], 1, 23, &err);
tm.tm_hour = kore_strtonum(tbuf[0], 10, 1, 23, &err);
if (err == KORE_RESULT_ERROR) {
kore_debug("misformed hour in http-date: '%s'", http_date);
goto out;
}
tm.tm_min = kore_strtonum(tbuf[1], 1, 59, &err);
tm.tm_min = kore_strtonum(tbuf[1], 10, 1, 59, &err);
if (err == KORE_RESULT_ERROR) {
kore_debug("misformed minutes in http-date: '%s'", http_date);
goto out;
}
tm.tm_sec = kore_strtonum(tbuf[2], 0, 60, &err);
tm.tm_sec = kore_strtonum(tbuf[2], 10, 0, 60, &err);
if (err == KORE_RESULT_ERROR) {
kore_debug("misformed seconds in http-date: '%s'", http_date);
goto out;