}
}
else if (lenp) {
- int conversion_error = 0;
char *endstr;
ctx->state = BODY_LENGTH;
errno = 0;
- ctx->remaining = strtol(lenp, &endstr, 10); /* we depend on ANSI */
-
- /* This protects us from over/underflow (the errno check),
- * non-digit chars in the string (excluding leading space)
- * (the endstr checks) and a negative number. Depending
- * on the strtol implementation, the errno check may also
- * trigger on an all whitespace string */
- if (errno || (endstr && *endstr) || (ctx->remaining < 0)) {
- conversion_error = 1;
- }
-
- if (conversion_error) {
+
+ /* Protects against over/underflow, non-digit chars in the
+ * string (excluding leading space) (the endstr checks)
+ * and a negative number. */
+ if (apr_strtoff(&ctx->remaining, lenp, &endstr, 10)
+ || *endstr || ctx->remaining < 0) {
apr_bucket_brigade *bb;
+ ctx->remaining = 0;
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,
"Invalid Content-Length");
r->read_chunked = 1;
}
else if (lenp) {
- int conversion_error = 0;
char *endstr;
- errno = 0;
- r->remaining = strtol(lenp, &endstr, 10); /* depend on ANSI */
-
- /* See comments in ap_http_filter() */
- if (errno || (endstr && *endstr) || (r->remaining < 0)) {
- conversion_error = 1;
- }
-
- if (conversion_error) {
+ if (apr_strtoff(&r->remaining, lenp, &endstr, 10)
+ || *endstr || r->remaining < 0) {
+ r->remaining = 0;
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Invalid Content-Length");
return HTTP_BAD_REQUEST;