X-Git-Url: https://unix4lyfe.org/gitweb/darkhttpd/blobdiff_plain/d777aacd985ee13dbdf04b223e86938294648b7c..HEAD:/darkhttpd.c diff --git a/darkhttpd.c b/darkhttpd.c index 53363bd..e15d8de 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -1865,7 +1865,10 @@ static void generate_dir_listing(struct connection *conn, const char *path) { listing = make_apbuf(); append(listing, "\n\n "); append(listing, conn->url); - append(listing, "\n\n\n

"); + append(listing, + "\n" + "\n" + "\n\n

"); append(listing, conn->url); append(listing, "

\n
\n");
 
@@ -2370,6 +2373,10 @@ static ssize_t send_from_file(const int s, const int fd,
 static void poll_send_reply(struct connection *conn)
 {
     ssize_t sent;
+    /* off_t can be wider than size_t, avoid overflow in send_len */
+    const size_t max_size_t = ~((size_t)0);
+    off_t send_len = conn->reply_length - conn->reply_sent;
+    if (send_len > max_size_t) send_len = max_size_t;
 
     assert(conn->state == SEND_REPLY);
     assert(!conn->header_only);
@@ -2377,14 +2384,13 @@ static void poll_send_reply(struct connection *conn)
         assert(conn->reply_length >= conn->reply_sent);
         sent = send(conn->socket,
             conn->reply + conn->reply_start + conn->reply_sent,
-            (size_t)(conn->reply_length - conn->reply_sent), 0);
+            (size_t)send_len, 0);
     }
     else {
         errno = 0;
         assert(conn->reply_length >= conn->reply_sent);
         sent = send_from_file(conn->socket, conn->reply_fd,
-            conn->reply_start + conn->reply_sent,
-            (size_t)(conn->reply_length - conn->reply_sent));
+            conn->reply_start + conn->reply_sent, (size_t)send_len);
         if (debug && (sent < 1))
             printf("send_from_file returned %lld (errno=%d %s)\n",
                 (long long)sent, errno, strerror(errno));