[PATCH] making ngx_http_parse_time support 1 digit day

Wandenberg Peixoto wandenberg at gmail.com
Fri Nov 9 14:37:50 UTC 2012


Hello!

I was checking a strange behavior when parsing dates coming from different
browsers with this function and observed that it not supports dates with
only one digit, it expect that the date comes with 01, 02, 03 ...
But as rfc822 and rfc2822 says the day can be 1, 2 , 3, ... 10, 15, ...
So I am proposing this patch to be compliant with the rfc.

I expect that this patch could be applied to nginx code.

--- src/http/ngx_http_parse_time.c    2012-02-28 08:31:05.000000000 -0300
+++ src/http/ngx_http_parse_time.c    2012-11-09 11:38:38.664036971 -0200
@@ -54,12 +54,17 @@ ngx_http_parse_time(u_char *value, size_
         }

     if (fmt != isoc) {
-        if (*p < '0' || *p > '9' || *(p + 1) < '0' || *(p + 1) > '9') {
+        if (*p < '0' || *p > '9' || ((*(p + 1) != ' ') && (*(p + 1) < '0'
|| *(p + 1) > '9'))) {
             return NGX_ERROR;
         }

-        day = (*p - '0') * 10 + *(p + 1) - '0';
-        p += 2;
+        if (*(p + 1) == ' ') {
+            day = (*p - '0');
+            p += 1;
+        } else {
+            day = (*p - '0') * 10 + *(p + 1) - '0';
+            p += 2;
+        }

         if (*p == ' ') {
             if (end - p < 18) {

Regards,
Wandenberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20121109/e2795fd3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ngx_http_parse_time_rfc822_one_or_two_digit_day.patch
Type: application/octet-stream
Size: 769 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20121109/e2795fd3/attachment.obj>


More information about the nginx-devel mailing list