[haiku-commits] haiku: hrev51012 - in src/apps/poorman/libhttpd: . src/apps/poorman

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 12 Mar 2017 10:44:39 +0100 (CET)

hrev51012 adds 1 changeset to branch 'master'
old head: fdd3fd9e0689e06570a1305ef0d59cae484f9f6b
new head: 4d8811742fa447ec05b4993a16a0931bc29aafab
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=4d8811742fa4+%5Efdd3fd9e0689

----------------------------------------------------------------------------

4d8811742fa4: Fix client hang when HEAD request is sent to PoorMan
  
  If a HEAD request was sent to PoorMan, for example from curl
  ("curl --HEAD http://x.x.x.x";) then the client would hang due to the 
connection
  never being closed.
  
  In PoorManServer::_Worker, after httpd_start_request() is called, a null
  file_address is used to detect when libhttpd has already sent a directory
  listing. In this situation, PoorMan assumes libhttpd already fully handled the
  request. However httpd_start_request() didn't properly set this flag for HEAD
  requests. In the if block for a null file_address, the file descriptor was
  incorrectly invalidated, which prevented the connection from closing. Fixing
  this revealed two more bugs. The first is libhttpd was not actually sending
  the http headers for HEAD directory listing requests. The second is
  PoorManServer would increment its hit count for HEAD directory listing
  requests. This change also refactors file_address to a more sensible name and
  type that reflects its use.
  
  Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
  
  Fixes #13347.

                        [ Kevin Wojniak <kainjow@xxxxxxxxxxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51012
Commit:      4d8811742fa447ec05b4993a16a0931bc29aafab
URL:         http://cgit.haiku-os.org/haiku/commit/?id=4d8811742fa4
Author:      Kevin Wojniak <kainjow@xxxxxxxxxxxxxxxxxxxxxxxx>
Date:        Sun Feb 26 12:49:23 2017 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Commit-Date: Sun Mar 12 09:39:09 2017 UTC

Ticket:      https://dev.haiku-os.org/ticket/13347

----------------------------------------------------------------------------

3 files changed, 10 insertions(+), 13 deletions(-)
src/apps/poorman/PoorManServer.cpp   | 11 ++++++-----
src/apps/poorman/libhttpd/libhttpd.c | 10 +++-------
src/apps/poorman/libhttpd/libhttpd.h |  2 +-

----------------------------------------------------------------------------

diff --git a/src/apps/poorman/PoorManServer.cpp 
b/src/apps/poorman/PoorManServer.cpp
index dacc2ac..faace73 100644
--- a/src/apps/poorman/PoorManServer.cpp
+++ b/src/apps/poorman/PoorManServer.cpp
@@ -317,11 +317,12 @@ int32 PoorManServer::_Worker(void* data)
        /*true means the connection is already handled
         *by the directory index generator in httpd_start_request().
         */
-       if (hc->file_address == (char*) 0) {
-               
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->SetHits(
-                       
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->GetHits() + 1
-               );
-               hc->conn_fd = -1;
+       if (hc->processed_directory_index == 1) {
+               if (hc->method == METHOD_GET) {
+                       
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->SetHits(
+                               
static_cast<PoorManApplication*>(be_app)->GetPoorManWindow()->GetHits() + 1
+                       );
+               }
                goto cleanup;
        }
        
diff --git a/src/apps/poorman/libhttpd/libhttpd.c 
b/src/apps/poorman/libhttpd/libhttpd.c
index ce22eeb..ab52cc4 100644
--- a/src/apps/poorman/libhttpd/libhttpd.c
+++ b/src/apps/poorman/libhttpd/libhttpd.c
@@ -1767,7 +1767,7 @@ httpd_get_conn( httpd_server* hs, int listen_fd, 
httpd_conn* hc )
     hc->last_byte_index = -1;
     hc->keep_alive = 0;
     hc->should_linger = 0;
-    hc->file_address = (char*) 0;
+    hc->processed_directory_index = 0;
     return GC_OK;
     }
 
@@ -2459,11 +2459,6 @@ httpd_close_conn( httpd_conn* hc, struct timeval* nowP )
     {
     make_log_entry( hc, nowP );
 
-    if ( hc->file_address != (char*) 0 )
-       {
-       //mmc_unmap( hc->file_address, &(hc->sb), nowP );
-       hc->file_address = (char*) 0;
-       }
     if ( hc->conn_fd >= 0 )
        {
        (void) close( hc->conn_fd );
@@ -2713,6 +2708,7 @@ ls( httpd_conn* hc )
        send_mime(
            hc, 200, ok200title, "", "", "text/html; charset=%s", (off_t) -1,
            hc->sb.st_mtime );
+       httpd_write_response( hc );
        free(de);
        }
     else if ( hc->method == METHOD_GET )
@@ -2948,6 +2944,7 @@ ls( httpd_conn* hc )
        free(de);
        return -1;
        }
+       hc->processed_directory_index = 1;
        return 0;
     }
 
@@ -3265,7 +3262,6 @@ if(hc->hs->do_list_dir){
        }
     else
        {
-       hc->file_address = (char*)1;
        send_mime(
            hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
            hc->sb.st_mtime );
diff --git a/src/apps/poorman/libhttpd/libhttpd.h 
b/src/apps/poorman/libhttpd/libhttpd.h
index f820071..71ce5ce 100644
--- a/src/apps/poorman/libhttpd/libhttpd.h
+++ b/src/apps/poorman/libhttpd/libhttpd.h
@@ -145,7 +145,7 @@ typedef struct {
     int should_linger;
     struct stat sb;
     int conn_fd;
-    char* file_address;
+    int processed_directory_index;
     } httpd_conn;
 
 /* Methods. */


Other related posts:

  • » [haiku-commits] haiku: hrev51012 - in src/apps/poorman/libhttpd: . src/apps/poorman - pulkomandy