On Sat, Jan 16, 2016 at 04:35:16AM +0000, Peter J. Philipp wrote:
> 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):

Here is my third attempt.  Someone correctly told me that off_t is signed.
This makes it difficult to make it clean as it was before my attempts.  But
take a look at this code and see what I mean.  The below is untested.

I set content_length to 0 because it's better than having a negative value
fly around the code execution path.

-peter


? 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:58:16 -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:58:16 -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];
@@ -386,6 +386,9 @@ server_partial_file_request(struct httpd
                    "byteranges; boundary=%ud", boundary);
                media = &multipart_media;
        }
+
+       if (content_length < 0)
+               content_length = 0;
 
        ret = server_response_http(clt, 206, media, content_length,
            MINIMUM(time(NULL), st->st_mtim.tv_sec));
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:58:17 -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 %qd\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 %qd \"%s\" \"%s\"\n",
                    srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
                    user, tstamp,
                    server_httpmethod_byid(desc->http_method),


Reply via email to