From 6f1e9f317640f652d66b4218cd30ea2005db5140 Mon Sep 17 00:00:00 2001 From: Peter Gaal Date: Tue, 5 Mar 2019 15:38:54 +0000 Subject: [PATCH] Update to version 2.29 from ACME source code --- INSTALL | 6 +-- README.md | 2 +- contrib/redhat-rpm/thttpd.spec | 2 +- libhttpd.c | 99 +++++++++++++++++----------------- libhttpd.h | 3 ++ samples/form.html | 15 ------ samples/formPost.c | 51 ------------------ samples/formPost.html | 6 --- samples/index.html | 11 ---- samples/mult.c | 18 ------- samples/simplecgi.c | 6 --- samples/viewData.c | 23 -------- thttpd.conf | 7 --- version.h | 2 +- 14 files changed, 58 insertions(+), 193 deletions(-) delete mode 100644 samples/form.html delete mode 100644 samples/formPost.c delete mode 100644 samples/formPost.html delete mode 100644 samples/index.html delete mode 100644 samples/mult.c delete mode 100644 samples/simplecgi.c delete mode 100644 samples/viewData.c delete mode 100644 thttpd.conf diff --git a/INSTALL b/INSTALL index 7b15219..a9c9e9b 100644 --- a/INSTALL +++ b/INSTALL @@ -20,9 +20,9 @@ Red Hat: On Red Hat Linux systems you can use RPM to install thttpd, like so: cd /usr/src/redhat/SOURCES - wget http://www.acme.com/software/thttpd/thttpd-2.28.tar.gz - rpm -ta thttpd-2.28.tar.gz - rpm -i /usr/src/redhat/RPMS/i386/thttpd-2.28-1.i386.rpm + wget http://www.acme.com/software/thttpd/thttpd-2.29.tar.gz + rpm -ta thttpd-2.29.tar.gz + rpm -i /usr/src/redhat/RPMS/i386/thttpd-2.29-1.i386.rpm Solaris: diff --git a/README.md b/README.md index acbc49b..d9c0be2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ tinyhttpd This is a github mirror of thttpd (http://www.acme.com/software/thttpd/) thttpd - tiny/turbo/throttling HTTP server - version 2.28 of 04Feb2018 + version 2.29 of 23May2018 thttpd is a simple, small, portable, fast, and secure HTTP server. diff --git a/contrib/redhat-rpm/thttpd.spec b/contrib/redhat-rpm/thttpd.spec index 4b5b3d8..6ee0fee 100644 --- a/contrib/redhat-rpm/thttpd.spec +++ b/contrib/redhat-rpm/thttpd.spec @@ -1,6 +1,6 @@ Summary: Throttleable lightweight httpd server Name: thttpd -Version: 2.28 +Version: 2.29 Release: 1 Group: Networking URL: http://www.acme.com/software/thttpd diff --git a/libhttpd.c b/libhttpd.c index 3814e6a..c6b1622 100644 --- a/libhttpd.c +++ b/libhttpd.c @@ -1210,6 +1210,9 @@ httpd_method_str( int method ) case METHOD_GET: return "GET"; case METHOD_HEAD: return "HEAD"; case METHOD_POST: return "POST"; + case METHOD_PUT: return "PUT"; + case METHOD_DELETE: return "DELETE"; + case METHOD_TRACE: return "TRACE"; default: return "UNKNOWN"; } } @@ -2028,6 +2031,12 @@ httpd_parse_request( httpd_conn* hc ) hc->method = METHOD_HEAD; else if ( strcasecmp( method_str, httpd_method_str( METHOD_POST ) ) == 0 ) hc->method = METHOD_POST; + else if ( strcasecmp( method_str, httpd_method_str( METHOD_PUT ) ) == 0 ) + hc->method = METHOD_PUT; + else if ( strcasecmp( method_str, httpd_method_str( METHOD_DELETE ) ) == 0 ) + hc->method = METHOD_DELETE; + else if ( strcasecmp( method_str, httpd_method_str( METHOD_TRACE ) ) == 0 ) + hc->method = METHOD_TRACE; else { httpd_send_err( hc, 501, err501title, "", err501form, method_str ); @@ -3567,54 +3576,45 @@ cgi( httpd_conn* hc ) int r; ClientData client_data; - if ( hc->method == METHOD_GET || hc->method == METHOD_POST ) + if ( hc->hs->cgi_limit != 0 && hc->hs->cgi_count >= hc->hs->cgi_limit ) { - if ( hc->hs->cgi_limit != 0 && hc->hs->cgi_count >= hc->hs->cgi_limit ) - { - httpd_send_err( - hc, 503, httpd_err503title, "", httpd_err503form, - hc->encodedurl ); - return -1; - } - ++hc->hs->cgi_count; - httpd_clear_ndelay( hc->conn_fd ); - r = fork( ); - if ( r < 0 ) - { - syslog( LOG_ERR, "fork - %m" ); - httpd_send_err( - hc, 500, err500title, "", err500form, hc->encodedurl ); - return -1; - } - if ( r == 0 ) - { - /* Child process. */ - sub_process = 1; - httpd_unlisten( hc->hs ); - cgi_child( hc ); - } - - /* Parent process. */ - syslog( LOG_DEBUG, "spawned CGI process %d for file '%.200s'", r, hc->expnfilename ); -#ifdef CGI_TIMELIMIT - /* Schedule a kill for the child process, in case it runs too long */ - client_data.i = r; - if ( tmr_create( (struct timeval*) 0, cgi_kill, client_data, CGI_TIMELIMIT * 1000L, 0 ) == (Timer*) 0 ) - { - syslog( LOG_CRIT, "tmr_create(cgi_kill child) failed" ); - exit( 1 ); - } -#endif /* CGI_TIMELIMIT */ - hc->status = 200; - hc->bytes_sent = CGI_BYTECOUNT; - hc->should_linger = 0; + httpd_send_err( + hc, 503, httpd_err503title, "", httpd_err503form, + hc->encodedurl ); + return -1; } - else + ++hc->hs->cgi_count; + httpd_clear_ndelay( hc->conn_fd ); + r = fork( ); + if ( r < 0 ) { + syslog( LOG_ERR, "fork - %m" ); httpd_send_err( - hc, 501, err501title, "", err501form, httpd_method_str( hc->method ) ); + hc, 500, err500title, "", err500form, hc->encodedurl ); return -1; } + if ( r == 0 ) + { + /* Child process. */ + sub_process = 1; + httpd_unlisten( hc->hs ); + cgi_child( hc ); + } + + /* Parent process. */ + syslog( LOG_DEBUG, "spawned CGI process %d for file '%.200s'", r, hc->expnfilename ); +#ifdef CGI_TIMELIMIT + /* Schedule a kill for the child process, in case it runs too long */ + client_data.i = r; + if ( tmr_create( (struct timeval*) 0, cgi_kill, client_data, CGI_TIMELIMIT * 1000L, 0 ) == (Timer*) 0 ) + { + syslog( LOG_CRIT, "tmr_create(cgi_kill child) failed" ); + exit( 1 ); + } +#endif /* CGI_TIMELIMIT */ + hc->status = 200; + hc->bytes_sent = CGI_BYTECOUNT; + hc->should_linger = 0; return 0; } @@ -3637,14 +3637,6 @@ really_start_request( httpd_conn* hc, struct timeval* nowP ) expnlen = strlen( hc->expnfilename ); - if ( hc->method != METHOD_GET && hc->method != METHOD_HEAD && - hc->method != METHOD_POST ) - { - httpd_send_err( - hc, 501, err501title, "", err501form, httpd_method_str( hc->method ) ); - return -1; - } - /* Stat the file. */ if ( stat( hc->expnfilename, &hc->sb ) < 0 ) { @@ -3855,6 +3847,13 @@ really_start_request( httpd_conn* hc, struct timeval* nowP ) return -1; } + if ( hc->method != METHOD_GET && hc->method != METHOD_HEAD ) + { + httpd_send_err( + hc, 501, err501title, "", err501form, httpd_method_str( hc->method ) ); + return -1; + } + /* Fill in last_byte_index, if necessary. */ if ( hc->got_range && ( hc->last_byte_index == -1 || hc->last_byte_index >= hc->sb.st_size ) ) diff --git a/libhttpd.h b/libhttpd.h index 7805546..e707bc7 100644 --- a/libhttpd.h +++ b/libhttpd.h @@ -152,6 +152,9 @@ typedef struct { #define METHOD_GET 1 #define METHOD_HEAD 2 #define METHOD_POST 3 +#define METHOD_PUT 4 +#define METHOD_DELETE 5 +#define METHOD_TRACE 6 /* States for checked_state. */ #define CHST_FIRSTWORD 0 diff --git a/samples/form.html b/samples/form.html deleted file mode 100644 index 9897c56..0000000 --- a/samples/form.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - form submition - - - -
-
-
-
-
- - diff --git a/samples/formPost.c b/samples/formPost.c deleted file mode 100644 index 143ce99..0000000 --- a/samples/formPost.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#define MAXLEN 80 -#define EXTRA 5 -#define MAXINPUT MAXLEN+EXTRA+2 -#define DATAFILE "./data.txt" - -void decode(char *src, char *last, char *dest){ - for (; src != last; src++, dest++) { - if(*src == '+'){ - *dest = ' '; - }else if(*src == '%'){ - int code; - if(sscanf(src+1, "%2x", &code) != 1){ - code = '?'; - } - *dest = code; - src += 2; - }else{ - *dest = *src; - } - } - *dest = '\n'; - *++dest = '\0'; -} - -int main(void){ - char *lenstr; - char input[MAXINPUT], data[MAXINPUT]; - long len; - printf("%s%c%c\n", "Content-Type: text/html;charset=iso-8859-1", 13, 10); - printf("Reponse\n"); - lenstr = getenv("CONTENT_LENGTH"); - if(lenstr == NULL || sscanf(lenstr, "%ld", &len) != 1 || len > MAXLEN){ - printf("

Error in invocation- worng form probably"); - }else{ - FILE *f; - fgets(input, len+1, stdin); - decode(input+EXTRA, input+len, data); - f = fopen(DATAFILE, "a"); - if(f == NULL){ - printf("

Sorry, cannot store your data."); - }else{ - fputs(data, f); - } - fclose(f); - printf("

Thank you! the following contribution of yours has been stored:
%s", data); - printf("
View content of Data file"); - } - return 0; -} diff --git a/samples/formPost.html b/samples/formPost.html deleted file mode 100644 index 574fa70..0000000 --- a/samples/formPost.html +++ /dev/null @@ -1,6 +0,0 @@ -

-
Your input (80 chars max.):
-
-
-
diff --git a/samples/index.html b/samples/index.html deleted file mode 100644 index 0e30700..0000000 --- a/samples/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Sample page running on thttpd - - - -

Hello world!

- - diff --git a/samples/mult.c b/samples/mult.c deleted file mode 100644 index 9725240..0000000 --- a/samples/mult.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -int main(void) -{ - char *data; - long m,n; - printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1",13,10); - printf("Multiplication results\n"); - printf("

Multiplication results

\n"); - data = getenv("QUERY_STRING"); - if(data == NULL) - printf("

Error! Error in passing data from form to script."); - else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2) - printf("

Error! Invalid data. Data must be numeric."); - else - printf("

The product of %ld and %ld is %ld.",m,n,m*n); - return 0; -} diff --git a/samples/simplecgi.c b/samples/simplecgi.c deleted file mode 100644 index a4b8d91..0000000 --- a/samples/simplecgi.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -int main(void) { - printf("Content-Type: text/plain;charset=us-ascii\n\n"); - printf("Hello world in C\n\n"); - return 0; -} diff --git a/samples/viewData.c b/samples/viewData.c deleted file mode 100644 index 7a17279..0000000 --- a/samples/viewData.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#define DATAFILE "./data.txt" - -int main (void){ - FILE *f = fopen(DATAFILE, "r"); - int ch; - if(f == NULL){ - printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1", 13, 10); - printf("Failure\n"); - printf("

Unable to open data file, sorry!

"); - }else{ - printf("%s%c%c\n", "Content-Type: text/html;charset=iso-8859-1", 13, 10); - printf(""); - } - printf("
Go back"); - return 0; -} diff --git a/thttpd.conf b/thttpd.conf deleted file mode 100644 index 6565b63..0000000 --- a/thttpd.conf +++ /dev/null @@ -1,7 +0,0 @@ -dir=/usr/local/www -user=larry -port=80 -host=0.0.0.0 -cgipat=**.cgi -logfile=/usr/local/www/logs/thttpd_log -pidfile=/var/run/thttpd.pid diff --git a/version.h b/version.h index d0ea258..8d841b9 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,7 @@ #ifndef _VERSION_H_ #define _VERSION_H_ -#define SERVER_SOFTWARE "thttpd/2.28 04Feb2018" +#define SERVER_SOFTWARE "thttpd/2.29 23May2018" #define SERVER_ADDRESS "http://www.acme.com/software/thttpd/" #endif /* _VERSION_H_ */