You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2002/07/14 15:18:58 UTC

cvs commit: httpd-2.0/modules/http http_protocol.c

jim         2002/07/14 06:18:58

  Modified:    modules/http http_protocol.c
  Log:
  Streamline the handling of C-L values in the common case by using
  the known properties of ANSI strtol.
  
  Revision  Changes    Path
  1.446     +19 -30    httpd-2.0/modules/http/http_protocol.c
  
  Index: http_protocol.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/http/http_protocol.c,v
  retrieving revision 1.445
  retrieving revision 1.446
  diff -u -r1.445 -r1.446
  --- http_protocol.c	13 Jul 2002 18:16:33 -0000	1.445
  +++ http_protocol.c	14 Jul 2002 13:18:58 -0000	1.446
  @@ -797,27 +797,23 @@
               }
           }
           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);
  +            ctx->state = BODY_LENGTH;
  +            errno = 0;
  +            ctx->remaining = strtol(lenp, &endstr, 10);	/* we depend on ANSI */
   
  -                if (errno || (endstr && *endstr)) {
  -                    conversion_error = 1; 
  -                }
  +            /* 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 (*pos != '\0' || conversion_error) {
  +            if (conversion_error) {
                   apr_bucket_brigade *bb;
   
                   ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,
  @@ -1710,25 +1706,18 @@
           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; 
  -            }
  +        /* See comments in ap_http_filter() */
  +        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;