On Fri, Jan 15, 2016 at 08:36:05PM +0000, Peter J. Philipp wrote:
> Hello,
> 
> I had nothing better to do tonight after work so I read a little in httpd.
> I have come up with a patch for i386 and any architecture where off_t != 
> size_t.
> 
> So on i386 there is this:
> 
> uranus$ ./sizetest
> off_t = 8
> size_t = 4
> 
> and I have these files in a directory:
> 
> uranus$ ls -lhi
> total 12672
> 364207 -rw-r--r--  3 root  daemon   4.9G Jan 15 21:06 output.txt
> 364207 -rw-r--r--  3 root  daemon   4.9G Jan 15 21:06 output2.txt
> 364207 -rw-r--r--  3 root  daemon   4.9G Jan 15 21:06 output3.txt
> 
> A download (cancelled, but it doesn't matter) of the httpd without my patch
> looks like so:
> 
> default 192.168.1.127 - - [15/Jan/2016:21:11:55 +0100] "GET 
> /public/output2.txt HTTP/1.1" 200 948961280 "http://192.168.1.1/public/"; 
> "Mozilla/5.0 (X11; OpenBSD amd64) AppleWebKit/537.36 (KHTML, like Gecko) 
> Chrome/44.0.2403.157 Safari/537.36"
> 
> A download (cancelled again) of the httpd with my patch looks like so:
> 
> default 192.168.1.127 - - [15/Jan/2016:21:18:07 +0100] "GET 
> /public/output3.txt HTTP/1.1" 200 5243928576 "http://192.168.1.1/public/"; 
> "Mozilla/5.0 (X11; OpenBSD amd64) AppleWebKit/537.36 (KHTML, like Gecko) 
> Chrome/44.0.2403.157 Safari/537.36"
> 
> It looks accurate in this case.  Checking again with ls:
> 
> uranus$ ls -li output3.txt  
> 364207 -rw-r--r--  3 root  daemon  5243928576 Jan 15 21:06 output3.txt
> 
> Absolutely.
> 
> patch follows:
> 
> Cheers,
> -peter
> 
> ? httpd.patch
> Index: httpd.h
> ===================================================================
> RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
> retrieving revision 1.96
> diff -u -p -u -r1.96 httpd.h
> --- httpd.h   3 Aug 2015 11:45:17 -0000       1.96
> +++ httpd.h   15 Jan 2016 20:19:12 -0000
> @@ -602,7 +602,7 @@ const char *
>        server_http_host(struct sockaddr_storage *, char *, size_t);
>  char *server_http_parsehost(char *, char *, size_t, int *);
>  ssize_t       server_http_time(time_t, char *, size_t);
> -int   server_log_http(struct client *, u_int, size_t);
> +int   server_log_http(struct client *, u_int, off_t);
>  
>  /* server_file.c */
>  int   server_file(struct httpd *, struct client *);
> Index: server_http.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
> retrieving revision 1.96
> diff -u -p -u -r1.96 server_http.c
> --- server_http.c     31 Jul 2015 00:10:51 -0000      1.96
> +++ server_http.c     15 Jan 2016 20:19:12 -0000
> @@ -1450,7 +1450,7 @@ server_httperror_cmp(const void *a, cons
>  }
>  
>  int
> -server_log_http(struct client *clt, u_int code, size_t len)
> +server_log_http(struct client *clt, u_int code, off_t len)
>  {
>       static char              tstamp[64];
>       static char              ip[INET6_ADDRSTRLEN];
> @@ -1511,7 +1511,7 @@ server_log_http(struct client *clt, u_in
>                       goto done;
>  
>               ret = evbuffer_add_printf(clt->clt_log,
> -                 "%s %s - %s [%s] \"%s %s%s%s%s%s\" %03d %zu\n",
> +                 "%s %s - %s [%s] \"%s %s%s%s%s%s\" %03d %qu\n",
>                   srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
>                   user, tstamp,
>                   server_httpmethod_byid(desc->http_method),
> @@ -1559,7 +1559,7 @@ server_log_http(struct client *clt, u_in
>  
>               ret = evbuffer_add_printf(clt->clt_log,
>                   "%s %s - %s [%s] \"%s %s%s%s%s%s\""
> -                 " %03d %zu \"%s\" \"%s\"\n",
> +                 " %03d %qu \"%s\" \"%s\"\n",
>                   srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
>                   user, tstamp,
>                   server_httpmethod_byid(desc->http_method),


Hello again,

I couldn't sleep because for some reason my head was spinning around this 
code.  In sleep I reviewed what I remembered of this code and noticed two
things.

1.  My patch was against 5.8 not -current, so it needed special hand fixing.

2.  The "Range" code required the same attention as my original attention.

I'm gonna need someone to look over my changes closely that I'm gonna put
forward next, because -current httpd doesn't compile on my system due to
some changes in SSL, and I don't want to fully go -current just yet on this
box (my only i386 box).  The following has a change in content_length from
size_t to off_t in function server_partial_file_request() because it does this:

                content_length = range->end - range->start + 1;

and range->end and range->start are both off_t.

Here then the patches against -current (need review and testing):


? httpd.patch
Index: httpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.102
diff -u -p -u -r1.102 httpd.h
--- httpd.h     2 Dec 2015 15:13:00 -0000       1.102
+++ httpd.h     16 Jan 2016 04:22:50 -0000
@@ -597,7 +597,7 @@ const char *
         server_http_host(struct sockaddr_storage *, char *, size_t);
 char   *server_http_parsehost(char *, char *, size_t, int *);
 ssize_t         server_http_time(time_t, char *, size_t);
-int     server_log_http(struct client *, unsigned int, size_t);
+int     server_log_http(struct client *, unsigned int, off_t);
 
 /* server_file.c */
 int     server_file(struct httpd *, struct client *);
Index: server_file.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_file.c,v
retrieving revision 1.60
diff -u -p -u -r1.60 server_file.c
--- server_file.c       3 Aug 2015 11:45:17 -0000       1.60
+++ server_file.c       16 Jan 2016 04:22:50 -0000
@@ -303,7 +303,7 @@ server_partial_file_request(struct httpd
        struct media_type       *media, multipart_media;
        struct range            *range;
        struct evbuffer         *evb = NULL;
-       size_t                   content_length;
+       off_t                    content_length;
        int                      code = 500, fd = -1, i, nranges, ret;
        uint32_t                 boundary;
        char                     content_range[64];
Index: server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.103
diff -u -p -u -r1.103 server_http.c
--- server_http.c       7 Dec 2015 20:30:17 -0000       1.103
+++ server_http.c       16 Jan 2016 04:22:51 -0000
@@ -1443,7 +1443,7 @@ server_httperror_cmp(const void *a, cons
 }
 
 int
-server_log_http(struct client *clt, unsigned int code, size_t len)
+server_log_http(struct client *clt, unsigned int code, off_t len)
 {
        static char              tstamp[64];
        static char              ip[INET6_ADDRSTRLEN];
@@ -1504,7 +1504,7 @@ server_log_http(struct client *clt, unsi
                        goto done;
 
                ret = evbuffer_add_printf(clt->clt_log,
-                   "%s %s - %s [%s] \"%s %s%s%s%s%s\" %03d %zu\n",
+                   "%s %s - %s [%s] \"%s %s%s%s%s%s\" %03d %qu\n",
                    srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
                    user, tstamp,
                    server_httpmethod_byid(desc->http_method),
@@ -1552,7 +1552,7 @@ server_log_http(struct client *clt, unsi
 
                ret = evbuffer_add_printf(clt->clt_log,
                    "%s %s - %s [%s] \"%s %s%s%s%s%s\""
-                   " %03d %zu \"%s\" \"%s\"\n",
+                   " %03d %qu \"%s\" \"%s\"\n",
                    srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
                    user, tstamp,
                    server_httpmethod_byid(desc->http_method),

Reply via email to