diff --git a/src/http-header-glue.c b/src/http-header-glue.c index ab0c88cb..8f50edf5 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -158,8 +158,8 @@ int http_response_redirect_to_directory(server *srv, connection *con) { case AF_INET: if (NULL == (he = gethostbyaddr((char *)&our_addr.ipv4.sin_addr, sizeof(struct in_addr), AF_INET))) { log_error_write(srv, __FILE__, __LINE__, - "SSSS", "NOTICE: gethostbyaddr failed: ", - hstrerror(h_errno), ", using ip-address instead"); + "SdSS", "NOTICE: gethostbyaddr failed: ", + h_errno, ", using ip-address instead"); buffer_append_string(o, inet_ntoa(our_addr.ipv4.sin_addr)); } else { diff --git a/src/mod_cgi.c b/src/mod_cgi.c index 9f47e4f3..8ac37578 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -862,9 +862,15 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer * buffer_prepare_append(p->tmp_buf, ds->key->used + 2); for (j = 0; j < ds->key->used - 1; j++) { - p->tmp_buf->ptr[p->tmp_buf->used++] = - isalpha((unsigned char)ds->key->ptr[j]) ? - toupper((unsigned char)ds->key->ptr[j]) : '_'; + char cr = '_'; + if (light_isalpha(ds->key->ptr[j])) { + /* upper-case */ + cr = ds->key->ptr[j] & ~32; + } else if (light_isdigit(ds->key->ptr[j])) { + /* copy */ + cr = ds->key->ptr[j]; + } + p->tmp_buf->ptr[p->tmp_buf->used++] = cr; } p->tmp_buf->ptr[p->tmp_buf->used++] = '\0'; diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index 824fdd6d..9a88fd83 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -690,8 +690,8 @@ static int fcgi_spawn_connection(server *srv, if (NULL == (he = gethostbyname(host->host->ptr))) { log_error_write(srv, __FILE__, __LINE__, - "ssb", "gethostbyname failed: ", - hstrerror(h_errno), host->host); + "sdb", "gethostbyname failed: ", + h_errno, host->host); return -1; } @@ -1512,9 +1512,15 @@ static int fcgi_env_add_request_headers(server *srv, connection *con, plugin_dat buffer_prepare_append(srv->tmp_buf, ds->key->used + 2); for (j = 0; j < ds->key->used - 1; j++) { - srv->tmp_buf->ptr[srv->tmp_buf->used++] = - light_isalpha(ds->key->ptr[j]) ? - ds->key->ptr[j] & ~32 : '_'; + char c = '_'; + if (light_isalpha(ds->key->ptr[j])) { + /* upper-case */ + c = ds->key->ptr[j] & ~32; + } else if (light_isdigit(ds->key->ptr[j])) { + /* copy */ + c = ds->key->ptr[j]; + } + srv->tmp_buf->ptr[srv->tmp_buf->used++] = c; } srv->tmp_buf->ptr[srv->tmp_buf->used++] = '\0'; diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 7f0b579d..efb49122 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -670,8 +670,8 @@ static int scgi_spawn_connection(server *srv, if (NULL == (he = gethostbyname(host->host->ptr))) { log_error_write(srv, __FILE__, __LINE__, - "ssb", "gethostbyname failed: ", - hstrerror(h_errno), host->host); + "sdb", "gethostbyname failed: ", + h_errno, host->host); return -1; } diff --git a/src/mod_ssi.c b/src/mod_ssi.c index 45201b10..af70e36c 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -172,9 +172,15 @@ static int ssi_env_add_request_headers(server *srv, connection *con, plugin_data buffer_prepare_append(srv->tmp_buf, ds->key->used + 2); for (j = 0; j < ds->key->used - 1; j++) { - srv->tmp_buf->ptr[srv->tmp_buf->used++] = - isalpha((unsigned char)ds->key->ptr[j]) ? - toupper((unsigned char)ds->key->ptr[j]) : '_'; + char c = '_'; + if (light_isalpha(ds->key->ptr[j])) { + /* upper-case */ + c = ds->key->ptr[j] & ~32; + } else if (light_isdigit(ds->key->ptr[j])) { + /* copy */ + c = ds->key->ptr[j]; + } + srv->tmp_buf->ptr[srv->tmp_buf->used++] = c; } srv->tmp_buf->ptr[srv->tmp_buf->used] = '\0'; diff --git a/src/network.c b/src/network.c index 66075cdc..2d475afa 100644 --- a/src/network.c +++ b/src/network.c @@ -202,8 +202,8 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) { struct hostent *he; if (NULL == (he = gethostbyname(host))) { log_error_write(srv, __FILE__, __LINE__, - "sss", "gethostbyname failed: ", - hstrerror(h_errno), host); + "sds", "gethostbyname failed: ", + h_errno, host); return -1; } diff --git a/tests/docroot/www/Makefile.am b/tests/docroot/www/Makefile.am index 0b9af0b8..5f93f3da 100644 --- a/tests/docroot/www/Makefile.am +++ b/tests/docroot/www/Makefile.am @@ -1,4 +1,4 @@ EXTRA_DIST=cgi.php cgi.pl dummydir index.html index.txt phpinfo.php \ phpself.php redirect.php cgi-pathinfo.pl phphost.php pathinfo.php \ - nph-status.pl prefix.fcgi + nph-status.pl prefix.fcgi get-header.pl SUBDIRS=go indexfile expire diff --git a/tests/mod-cgi.t b/tests/mod-cgi.t index 763d859c..8b48ae5d 100755 --- a/tests/mod-cgi.t +++ b/tests/mod-cgi.t @@ -8,7 +8,7 @@ BEGIN { use strict; use IO::Socket; -use Test::More tests => 6; +use Test::More tests => 9; use LightyTest; my $tf = LightyTest->new(); @@ -46,5 +46,29 @@ EOF $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); ok($tf->handle_http($t) == 0, 'NPH + perl, Bug #14'); +$t->{REQUEST} = ( <{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'CGI/1.1' } ); +ok($tf->handle_http($t) == 0, 'cgi-env: GATEWAY_INTERFACE'); + +$t->{REQUEST} = ( <{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'foo' } ); +ok($tf->handle_http($t) == 0, 'cgi-env: quoting headers with numbers'); + +$t->{REQUEST} = ( <{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ); +ok($tf->handle_http($t) == 0, 'cgi-env: HTTP_HOST'); + + ok($tf->stop_proc == 0, "Stopping lighttpd");