You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Jagielski <ji...@jaguNET.com> on 2002/07/11 16:46:33 UTC

[PATCH] Streamline C-L check

This patch basically just streamlines the response of 2.0 in the
normal case, where C-L is valid. We used to scan each and every
char of the field to make sure it was OK, to catch bad fields early.
That's fine, but not, IMO, at the expense of somewhat slower response
in the normal/OK case.


--- modules/http/Ohttp_protocol.c	Thu Jul 11 10:32:43 2002
+++ modules/http/http_protocol.c	Thu Jul 11 10:37:53 2002
@@ -797,27 +797,18 @@
             }
         }
         else if (lenp) {
-            const char *pos = lenp;
             int conversion_error = 0;
+            char *endstr;
 
-            /* This ensures that the number can not be negative. */
-            while (apr_isdigit(*pos) || apr_isspace(*pos)) {
-                ++pos;
-            }
-
-            if (*pos == '\0') {
-                char *endstr;
-
-                errno = 0;
-                ctx->state = BODY_LENGTH;
-                ctx->remaining = strtol(lenp, &endstr, 10);
+            errno = 0;
+            ctx->state = BODY_LENGTH;
+            ctx->remaining = strtol(lenp, &endstr, 10);	/* we depend on ANSI */
 
-                if (errno || (endstr && *endstr)) {
-                    conversion_error = 1; 
-                }
+            if (errno || (endstr && *endstr) || (ctx->remaining < 0)) {
+                 conversion_error = 1; 
             }
 
-            if (*pos != '\0' || conversion_error) {
+            if (conversion_error) {
                 apr_bucket_brigade *bb;
 
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,
@@ -1710,25 +1701,17 @@
         r->read_chunked = 1;
     }
     else if (lenp) {
-        const char *pos = lenp;
         int conversion_error = 0;
+        char *endstr;
 
-        while (apr_isdigit(*pos) || apr_isspace(*pos)) {
-            ++pos;
-        }
-
-        if (*pos == '\0') {
-            char *endstr;
+        errno = 0;
+        r->remaining = strtol(lenp, &endstr, 10); /* depend on ANSI */
 
-            errno = 0;
-            r->remaining = strtol(lenp, &endstr, 10);
-
-            if (errno || (endstr && *endstr)) {
-                conversion_error = 1; 
-            }
+        if (errno || (endstr && *endstr) || (r->remaining < 0)) {
+            conversion_error = 1; 
         }
 
-        if (*pos != '\0' || conversion_error) {
+        if (conversion_error) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                           "Invalid Content-Length");
             return HTTP_BAD_REQUEST;
-- 
===========================================================================
   Jim Jagielski   [|]   jim@jaguNET.com   [|]   http://www.jaguNET.com/
      "A society that will trade a little liberty for a little order
             will lose both and deserve neither" - T.Jefferson