From: Jim Jagielski Date: Tue, 18 Jun 2002 01:00:00 +0000 (+0000) Subject: Migrate from strtol to ap_strtol, and use its known capability X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dd54070089eca1e7ad3941c43b73afa3688e3a9;p=thirdparty%2Fapache%2Fhttpd.git Migrate from strtol to ap_strtol, and use its known capability PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@95746 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/main/http_core.c b/src/main/http_core.c index b0339d8eb10..f8090a581cf 100644 --- a/src/main/http_core.c +++ b/src/main/http_core.c @@ -2891,7 +2891,7 @@ static const char *set_limit_req_body(cmd_parms *cmd, core_dir_config *conf, * Instead we have an idiotic define in httpd.h that prevents * it from being used even when it is available. Sheesh. */ - conf->limit_req_body = (unsigned long)strtol(arg, (char **)NULL, 10); + conf->limit_req_body = (unsigned long)ap_strtol(arg, (char **)NULL, 10); return NULL; } diff --git a/src/main/http_protocol.c b/src/main/http_protocol.c index c234cd03b7c..b96a55e45b0 100644 --- a/src/main/http_protocol.c +++ b/src/main/http_protocol.c @@ -171,7 +171,7 @@ static enum byterange_token } if (ap_isdigit(*r->range)) - *start = strtol(r->range, (char **)&r->range, 10); + *start = ap_strtol(r->range, (char **)&r->range, 10); else *start = -1; @@ -186,7 +186,7 @@ static enum byterange_token ++r->range; if (ap_isdigit(*r->range)) - *end = strtol(r->range, (char **)&r->range, 10); + *end = ap_strtol(r->range, (char **)&r->range, 10); else *end = -1; @@ -1984,20 +1984,23 @@ API_EXPORT(int) ap_setup_client_block(request_rec *r, int read_policy) } else if (lenp) { const char *pos = lenp; + int conversion_error = 0; while (ap_isdigit(*pos) || ap_isspace(*pos)) ++pos; - if (*pos != '\0') { - ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, - "Invalid Content-Length %s", lenp); - return HTTP_BAD_REQUEST; + + if (*pos == '\0') { + char *endstr; + errno = 0; + r->remaining = ap_strtol(lenp, &endstr, 10); + if (errno || (endstr && *endstr)) { + conversion_error = 1; + } } - r->remaining = atol(lenp); - if (r->remaining < 0) { + if (*pos != '\0' || conversion_error) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, - "Request content-length of %s maps to negative number %ld", - lenp, r->remaining); + "Invalid Content-Length"); return HTTP_BAD_REQUEST; } } diff --git a/src/main/util.c b/src/main/util.c index 4fe57f3566e..7a2d502a5aa 100644 --- a/src/main/util.c +++ b/src/main/util.c @@ -1569,7 +1569,7 @@ static char x2c(const char *what) xstr[2]=what[0]; xstr[3]=what[1]; xstr[4]='\0'; - digit = os_toebcdic[0xFF & strtol(xstr, NULL, 16)]; + digit = os_toebcdic[0xFF & ap_strtol(xstr, NULL, 16)]; #endif /*CHARSET_EBCDIC*/ return (digit); } diff --git a/src/main/util_uri.c b/src/main/util_uri.c index e61b7ba52ba..802790aa829 100644 --- a/src/main/util_uri.c +++ b/src/main/util_uri.c @@ -428,7 +428,7 @@ API_EXPORT(int) ap_parse_uri_components(pool *p, const char *uri, ++s; uptr->port_str = ap_pstrndup(p, s, uri - s); if (uri != s) { - port = strtol(uptr->port_str, &endstr, 10); + port = ap_strtol(uptr->port_str, &endstr, 10); uptr->port = port; if (*endstr == '\0') { goto deal_with_path; @@ -483,7 +483,7 @@ API_EXPORT(int) ap_parse_hostinfo_components(pool *p, const char *hostinfo, ++s; uptr->port_str = ap_pstrdup(p, s); if (*s != '\0') { - uptr->port = (unsigned short)strtol(uptr->port_str, &endstr, 10); + uptr->port = (unsigned short)ap_strtol(uptr->port_str, &endstr, 10); if (*endstr == '\0') { return HTTP_OK; } diff --git a/src/modules/experimental/mod_auth_digest.c b/src/modules/experimental/mod_auth_digest.c index cb8cd3ee836..5d4ae6f047a 100644 --- a/src/modules/experimental/mod_auth_digest.c +++ b/src/modules/experimental/mod_auth_digest.c @@ -573,7 +573,7 @@ static const char *set_nonce_lifetime(cmd_parms *cmd, void *config, char *endptr; long lifetime; - lifetime = strtol(t, &endptr, 10); + lifetime = ap_strtol(t, &endptr, 10); if (endptr < (t+strlen(t)) && !ap_isspace(*endptr)) return ap_pstrcat(cmd->pool, "Invalid time in AuthDigestNonceLifetime: ", t, NULL); @@ -933,7 +933,7 @@ static int get_digest_rec(request_rec *r, digest_header_rec *resp) } if (resp->opaque) - resp->opaque_num = (unsigned long) strtol(resp->opaque, NULL, 16); + resp->opaque_num = (unsigned long) ap_strtol(resp->opaque, NULL, 16); resp->auth_hdr_sts = VALID; return OK; @@ -1375,7 +1375,7 @@ static int check_nc(const request_rec *r, const digest_header_rec *resp, if (!conf->check_nc || !client_mm) return OK; - nc = strtol(snc, &endptr, 16); + nc = ap_strtol(snc, &endptr, 16); if (endptr < (snc+strlen(snc)) && !ap_isspace(*endptr)) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Digest: invalid nc %s received - not a number", snc); diff --git a/src/modules/proxy/mod_proxy.c b/src/modules/proxy/mod_proxy.c index 7485901a16f..6cca3c07841 100644 --- a/src/modules/proxy/mod_proxy.c +++ b/src/modules/proxy/mod_proxy.c @@ -305,7 +305,7 @@ static int proxy_handler(request_rec *r) if (r->method_number == M_TRACE && (maxfwd_str = ap_table_get(r->headers_in, "Max-Forwards")) != NULL) { - long maxfwd = strtol(maxfwd_str, NULL, 10); + long maxfwd = ap_strtol(maxfwd_str, NULL, 10); if (maxfwd < 1) { int access_status; r->proxyreq = NOT_PROXY; diff --git a/src/modules/proxy/proxy_http.c b/src/modules/proxy/proxy_http.c index 6a12ea20642..6a9a4443fb8 100644 --- a/src/modules/proxy/proxy_http.c +++ b/src/modules/proxy/proxy_http.c @@ -517,7 +517,7 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url, content_length = ap_table_get(resp_hdrs, "Content-Length"); if (content_length != NULL) { - c->len = strtol(content_length, NULL, 10); + c->len = ap_strtol(content_length, NULL, 10); } /* Now add out bound headers set by other modules */ diff --git a/src/modules/proxy/proxy_util.c b/src/modules/proxy/proxy_util.c index 56bdfd6a374..d350412e938 100644 --- a/src/modules/proxy/proxy_util.c +++ b/src/modules/proxy/proxy_util.c @@ -1072,7 +1072,7 @@ int ap_proxy_is_ipaddr(struct dirconn_entry *This, pool *p) if (!ap_isdigit(*addr)) return 0; /* no digit at start of quad */ - ip_addr[quads] = strtol(addr, &tmp, 0); + ip_addr[quads] = ap_strtol(addr, &tmp, 0); if (tmp == addr) /* expected a digit, found something else */ return 0; @@ -1096,7 +1096,7 @@ int ap_proxy_is_ipaddr(struct dirconn_entry *This, pool *p) ++addr; - bits = strtol(addr, &tmp, 0); + bits = ap_strtol(addr, &tmp, 0); if (tmp == addr) /* expected a digit, found something else */ return 0; diff --git a/src/modules/standard/mod_mime_magic.c b/src/modules/standard/mod_mime_magic.c index 77e1f1b8cc9..2ec733f77c4 100644 --- a/src/modules/standard/mod_mime_magic.c +++ b/src/modules/standard/mod_mime_magic.c @@ -1110,7 +1110,7 @@ static int parse(server_rec *serv, pool *p, char *l, int lineno) } /* get offset, then skip over it */ - m->offset = (int) strtol(l, &t, 0); + m->offset = (int) ap_strtol(l, &t, 0); if (l == t) { ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_ERR, serv, MODNAME ": offset %s invalid", l); @@ -1145,7 +1145,7 @@ static int parse(server_rec *serv, pool *p, char *l, int lineno) if (*l == '+' || *l == '-') l++; if (ap_isdigit((unsigned char) *l)) { - m->in.offset = strtol(l, &t, 0); + m->in.offset = ap_strtol(l, &t, 0); if (*s == '-') m->in.offset = -m->in.offset; } @@ -1233,7 +1233,7 @@ static int parse(server_rec *serv, pool *p, char *l, int lineno) /* New-style anding: "0 byte&0x80 =0x80 dynamically linked" */ if (*l == '&') { ++l; - m->mask = signextend(serv, m, strtol(l, &l, 0)); + m->mask = signextend(serv, m, ap_strtol(l, &l, 0)); } else m->mask = ~0L; @@ -1311,7 +1311,7 @@ static int getvalue(server_rec *s, struct magic *m, char **p) m->vallen = slen; } else if (m->reln != 'x') - m->value.l = signextend(s, m, strtol(*p, p, 0)); + m->value.l = signextend(s, m, ap_strtol(*p, p, 0)); return 0; } diff --git a/src/modules/test/mod_rndchunk.c b/src/modules/test/mod_rndchunk.c index 0b9061c4c48..5ce5385fd43 100644 --- a/src/modules/test/mod_rndchunk.c +++ b/src/modules/test/mod_rndchunk.c @@ -128,12 +128,12 @@ error: ap_kill_timeout(r); return 0; } - seed = strtol(args, &endptr, 0); + seed = ap_strtol(args, &endptr, 0); if (!endptr || *endptr != ',') { goto error; } ++endptr; - count = strtol(endptr, &endptr, 0); + count = ap_strtol(endptr, &endptr, 0); srandom(seed); for (i = 0; i < count; ++i) { diff --git a/src/os/win32/mod_isapi.c b/src/os/win32/mod_isapi.c index 0f502e275f9..0065e929065 100644 --- a/src/os/win32/mod_isapi.c +++ b/src/os/win32/mod_isapi.c @@ -825,7 +825,7 @@ static const char *isapi_cmd_readaheadbuffer(cmd_parms *cmd, void *config, return err; } - if (((val = strtol(arg, (char **) &err, 10)) <= 0) || *err) + if (((val = ap_strtol(arg, (char **) &err, 10)) <= 0) || *err) return "ISAPIReadAheadBuffer must be a legitimate value."; ReadAheadBuffer = val;