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 <[email protected]>
Fixes #13347.
This commit is contained in:
committed by
Adrien Destugues
parent
fdd3fd9e06
commit
4d8811742f
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user