From 8b2e5bba8279010bcec7cc5126cbf46e470d8c60 Mon Sep 17 00:00:00 2001 From: cameronrich Date: Fri, 7 May 2010 10:39:58 +0000 Subject: [PATCH] fixes to axhttpd from Joe Pruett git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@170 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- crypto/crypto_misc.c | 2 +- httpd/axhttpd.c | 6 ++++-- httpd/proc.c | 31 +++++++++++++++++++------------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/crypto/crypto_misc.c b/crypto/crypto_misc.c index 40df4e024..a44c5c22a 100644 --- a/crypto/crypto_misc.c +++ b/crypto/crypto_misc.c @@ -131,12 +131,12 @@ EXP_FUNC void STDCALL RNG_initialize(const uint8_t *seed_buf, int size) a number that should be hard to find, due to the fact that it relies on knowing the private key */ memcpy(entropy_pool, seed_buf, ENTROPY_POOL_SIZE); + srand((long)entropy_pool); /* mix it up a little with a stack address */ for (i = 0; i < ENTROPY_POOL_SIZE/4; i++) ep[i] ^= seed_addr_val; - srand((long)entropy_pool); #endif } diff --git a/httpd/axhttpd.c b/httpd/axhttpd.c index 148d99a5f..bb54e487c 100644 --- a/httpd/axhttpd.c +++ b/httpd/axhttpd.c @@ -55,7 +55,8 @@ static void addcgiext(const char *tp); #if !defined(WIN32) static void reaper(int sigtype) { - wait3(NULL, WNOHANG, NULL); + while (wait3(NULL, WNOHANG, NULL) > 0) + continue; } #endif #endif @@ -446,7 +447,8 @@ static void handlenewconnection(int listenfd, int is_ssl) else *ipbuf = '\0'; - addconnection(connfd, ipbuf, is_ssl); + if (connfd != -1) /* check for error condition */ + addconnection(connfd, ipbuf, is_ssl); } #else diff --git a/httpd/proc.c b/httpd/proc.c index c90fa9790..3874c8fc2 100644 --- a/httpd/proc.c +++ b/httpd/proc.c @@ -119,7 +119,7 @@ static int procheadelem(struct connstruct *cn, char *buf) #endif cn->if_modified_since = -1; } - else if (strcmp(buf, "Host:") == 0) + else if (strcasecmp(buf, "Host:") == 0) { if (sanitizehost(value) == 0) { @@ -129,21 +129,24 @@ static int procheadelem(struct connstruct *cn, char *buf) my_strncpy(cn->server_name, value, MAXREQUESTLENGTH); } - else if (strcmp(buf, "Connection:") == 0 && strcmp(value, "close") == 0) + else if (strcasecmp(buf, "Connection:") == 0 && strcmp(value, "close") == 0) { cn->close_when_done = 1; } - else if (strcmp(buf, "If-Modified-Since:") == 0) + else if (strcasecmp(buf, "If-Modified-Since:") == 0) { cn->if_modified_since = tdate_parse(value); } - else if (strcmp(buf, "Expect:") == 0) + else if (strcasecmp(buf, "Expect:") == 0) { - send_error(cn, 417); /* expectation failed */ - return 0; + /* supposed to be safe to ignore 100-continue */ + if (strcasecmp(value, "100-continue") != 0) { + send_error(cn, 417); /* expectation failed */ + return 0; + } } #ifdef CONFIG_HTTP_HAS_AUTHORIZATION - else if (strcmp(buf, "Authorization:") == 0 && + else if (strcasecmp(buf, "Authorization:") == 0 && strncmp(value, "Basic ", 6) == 0) { int size; @@ -155,15 +158,15 @@ static int procheadelem(struct connstruct *cn, char *buf) } #endif #if defined(CONFIG_HTTP_HAS_CGI) - else if (strcmp(buf, "Content-Length:") == 0) + else if (strcasecmp(buf, "Content-Length:") == 0) { sscanf(value, "%d", &cn->content_length); } - else if (strcmp(buf, "Content-Type:") == 0) + else if (strcasecmp(buf, "Content-Type:") == 0) { my_strncpy(cn->cgicontenttype, value, MAXREQUESTLENGTH); } - else if (strcmp(buf, "Cookie:") == 0) + else if (strcasecmp(buf, "Cookie:") == 0) { my_strncpy(cn->cookie, value, MAXREQUESTLENGTH); } @@ -628,11 +631,15 @@ static void proccgi(struct connstruct *cn) /* Our stdout/stderr goes to the socket */ dup2(tpipe[1], 1); dup2(tpipe[1], 2); + close(tpipe[0]); + close(tpipe[1]); /* If it was a POST request, send the socket data to our stdin */ - if (cn->reqtype == TYPE_POST) + if (cn->reqtype == TYPE_POST) { dup2(spipe[0], 0); - else /* Otherwise we can shutdown the read side of the sock */ + close(spipe[0]); + close(spipe[1]); + } else /* Otherwise we can shutdown the read side of the sock */ shutdown(cn->networkdesc, 0); myargs[0] = cn->actualfile;