From: hno <> Date: Sat, 6 Jul 2002 18:37:40 +0000 (+0000) Subject: Be picky when we parse numeric configuration directives. Do not blindly X-Git-Tag: SQUID_3_0_PRE1~918 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c20d6fa82d774ccb9d28212acc5f34622957227;p=thirdparty%2Fsquid.git Be picky when we parse numeric configuration directives. Do not blindly accept junk as if it was 0 --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index e39c7387e8..cd46dc45a1 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.408 2002/06/23 14:50:06 hno Exp $ + * $Id: cache_cf.cc,v 1.409 2002/07/06 12:37:40 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -201,12 +201,36 @@ intlistFind(intlist * list, int i) return 0; } - /* - * Use this #define in all the parse*() functions. Assumes char *token is - * defined + * These functions is the same as atoi/l/f, except that they check for errors */ +static long +xatol(const char *token) +{ + char *end; + long ret = strtol(token, &end, 10); + if (ret == 0 && end == token) + self_destruct(); + return ret; +} + +static int +xatoi(const char *token) +{ + return xatol(token); +} + +static double +xatof(const char *token) +{ + char *end; + double ret = strtod(token, &end); + if (ret == 0 && end == token) + self_destruct(); + return ret; +} + int GetInteger(void) { @@ -485,7 +509,7 @@ parseTimeLine(time_t * tptr, const char *units) self_destruct(); if ((token = strtok(NULL, w_space)) == NULL) self_destruct(); - d = atof(token); + d = xatof(token); m = u; /* default to 'units' if none specified */ if (0 == d) (void) 0; @@ -533,7 +557,7 @@ parseBytesLine(size_t * bptr, const char *units) self_destruct(); if ((token = strtok(NULL, w_space)) == NULL) self_destruct(); - d = atof(token); + d = xatof(token); m = u; /* default to 'units' if none specified */ if (0.0 == d) (void) 0; @@ -1274,7 +1298,7 @@ parse_cachedir_option_readonly(SwapDir * sd, const char *option, const char *val { int read_only = 0; if (value) - read_only = atoi(value); + read_only = xatoi(value); else read_only = 1; sd->flags.read_only = read_only; @@ -1295,7 +1319,7 @@ parse_cachedir_option_maxsize(SwapDir * sd, const char *option, const char *valu if (!value) self_destruct(); - size = atoi(value); + size = xatoi(value); if (reconfiguring && sd->max_objsize != size) debug(3, 1) ("Cache dir '%s' max object size now %ld\n", sd->path, (long int) size); @@ -1459,13 +1483,13 @@ parse_peer(peer ** head) } else if (!strcasecmp(token, "multicast-responder")) { p->options.mcast_responder = 1; } else if (!strncasecmp(token, "weight=", 7)) { - p->weight = atoi(token + 7); + p->weight = xatoi(token + 7); } else if (!strncasecmp(token, "basetime=", 9)) { - p->basetime = atoi(token + 9); + p->basetime = xatoi(token + 9); } else if (!strcasecmp(token, "closest-only")) { p->options.closest_only = 1; } else if (!strncasecmp(token, "ttl=", 4)) { - p->mcast.ttl = atoi(token + 4); + p->mcast.ttl = xatoi(token + 4); if (p->mcast.ttl < 0) p->mcast.ttl = 0; if (p->mcast.ttl > 128) @@ -1496,7 +1520,7 @@ parse_peer(peer ** head) p->login = xstrdup(token + 6); rfc1738_unescape(p->login); } else if (!strncasecmp(token, "connect-timeout=", 16)) { - p->connect_timeout = atoi(token + 16); + p->connect_timeout = xatoi(token + 16); #if USE_CACHE_DIGESTS } else if (!strncasecmp(token, "digest-url=", 11)) { p->digest_url = xstrdup(token + 11); @@ -1504,7 +1528,7 @@ parse_peer(peer ** head) } else if (!strcasecmp(token, "allow-miss")) { p->options.allow_miss = 1; } else if (!strncasecmp(token, "max-conn=", 9)) { - p->max_conn = atoi(token + 9); + p->max_conn = xatoi(token + 9); } else { debug(3, 0) ("parse_peer: token='%s'\n", token); self_destruct(); @@ -2253,10 +2277,10 @@ parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token) /* host:port */ host = token; *t = '\0'; - port = (unsigned short) atoi(t + 1); + port = (unsigned short) xatoi(t + 1); if (0 == port) self_destruct(); - } else if ((port = atoi(token)) > 0) { + } else if ((port = xatoi(token)) > 0) { /* port */ } else { self_destruct(); @@ -2334,10 +2358,10 @@ parse_https_port_list(https_port_list ** head) /* host:port */ host = token; *t = '\0'; - port = (unsigned short) atoi(t + 1); + port = (unsigned short) xatoi(t + 1); if (0 == port) self_destruct(); - } else if ((port = atoi(token)) > 0) { + } else if ((port = xatoi(token)) > 0) { /* port */ } else { self_destruct(); @@ -2361,7 +2385,7 @@ parse_https_port_list(https_port_list ** head) safe_free(s->key); s->key = xstrdup(token + 4); } else if (strncmp(token, "version=", 8) == 0) { - s->version = atoi(token + 8); + s->version = xatoi(token + 8); } else if (strncmp(token, "options=", 8) == 0) { safe_free(s->options); s->options = xstrdup(token + 8);