httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <wr...@rowe-clan.net>
Subject RE: PR 6973 / 1.3.15 showstopper
Date Fri, 15 Dec 2000 23:54:38 GMT
As Tony noted, there was one error below (see -/+).  Also,
note that  nolead = (off == range);  actually does something,
in the case that *range == "X" or some other nonsense.

Jim, Tony's and I have both parsed this against the spec ... it is
actually a little liberal in that <sp>#<sp>-<sp>#<sp> is allowed,
but my reading of the spec is that only <sp>#-#<sp> is permitted.
Which reading do you agree with?

If you like, feel free to apply, and change to exclude the spaces
permitted between #-# if you rather.

Bill

> -----Original Message-----
> From: William A. Rowe, Jr. [mailto:wrowe@rowe-clan.net]
> Sent: Friday, December 15, 2000 4:34 PM
> To: new-httpd@apache.org
> Subject: RE: PR 6973 / 1.3.15 showstopper
> 
> 
> Not a diff... this is a little meaty, needs reading ...
> not the prettiest thing either, but moderately optimal, fel 
> free to improve.
> 
> static int parse_byterange(char *range, long clength, long 
> *start, long *end)
> {
>     int nolead, notail;
>     char *off, *off2;
>     long lead, tail;
>     
>     /* Look for leading dash */
>     while (ap_isspace(*range)) 
>         ++range;
>     if (*(range) == '-') {
>         nolead = 1;
-         off = range;
+         off = range + 1;
>     }
>     else {
>         /* Parse first value */
>         lead = strtol(range, &off, 10);
>         nolead = (off == range);
> 
>         /* Confirm and skip dash */
>         while (ap_isspace(*off)) 
>             ++off;
>         if (*(off) != '-') /* Dash is -required- */
>             return 0;
>         ++off;
>     }
> 
>     /* Parse second value */
>     tail = strtol(off, &off2, 10);
>     notail = (off == off2);
> 
>     /* Confirm end of text */
>     while (ap_isspace(*off2)) 
>         ++off2;
>     if (*off2) /* nothing else allowed */
>         return 0;
> 
>     if (nolead) 
>     {
>         if (notail)      /* "-" alone is insufficient */
>             return 0;
>                          /* else format was "-5", could be "--5" */
>         *start = clength - tail;
>         *end = clength - 1;
> 
>         if (*start < 0)  /* Correct "-5" longer than clength */
> 	    *start = 0;
>     }
>     else {
>         *start = lead;
>         if (notail)      /* format was "5-" */
>             *end = clength - 1;
>         else {            
>                          /* format was "5-6", could be "5-4" */
>             *end = tail;
> 
>             if (*end >= clength) /* Correct end of "5-9" past 
> clength */
>                 *end = clength - 1;
>         }
>     }
> 
>     if (*start > *end)  /* "5-4", "--5", start beyond length 
> all fall out */
> 	return 0;
> 
>     return 1;
> }
> 
> 
> 

Mime
View raw message