diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-19 13:59:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-19 13:59:58 +0200 |
commit | ad29ba73ee00d4c78b3ab85a6b943a8c63075f50 (patch) | |
tree | 379dff42faf0a7eeedde0d7d23f7e3a8980b4122 | |
parent | d1a2fa2a4e013960bf56dfef8a71ed2d08fc756b (diff) | |
download | busybox-w32-ad29ba73ee00d4c78b3ab85a6b943a8c63075f50.tar.gz busybox-w32-ad29ba73ee00d4c78b3ab85a6b943a8c63075f50.tar.bz2 busybox-w32-ad29ba73ee00d4c78b3ab85a6b943a8c63075f50.zip |
httpd: require "HTTP/xyz" at the end of request line
function old new delta
handle_incoming_and_exit 2379 2362 -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-17) Total: -17 bytes
text data bss dec hex filename
981787 485 7296 989568 f1980 busybox_old
981779 485 7296 989560 f1978 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/httpd.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 0b5d2b481..f8a1e2556 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -2128,7 +2128,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2128 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH | 2128 | #if ENABLE_FEATURE_HTTPD_BASIC_AUTH |
2129 | smallint authorized = -1; | 2129 | smallint authorized = -1; |
2130 | #endif | 2130 | #endif |
2131 | char http_major_version; | ||
2132 | char *HTTP_slash; | 2131 | char *HTTP_slash; |
2133 | 2132 | ||
2134 | /* Allocation of iobuf is postponed until now | 2133 | /* Allocation of iobuf is postponed until now |
@@ -2191,16 +2190,12 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2191 | if (urlp[0] != '/') | 2190 | if (urlp[0] != '/') |
2192 | send_headers_and_exit(HTTP_BAD_REQUEST); | 2191 | send_headers_and_exit(HTTP_BAD_REQUEST); |
2193 | 2192 | ||
2194 | /* Find end of URL and parse HTTP version, if any */ | 2193 | /* Find end of URL */ |
2195 | //TODO: maybe just reject all queries which have no " HTTP/xyz" suffix? | 2194 | HTTP_slash = strchr(urlp, ' '); |
2196 | //Then 'http_major_version' can be deleted | ||
2197 | http_major_version = ('0' - 1); /* "less than 0th" version */ | ||
2198 | HTTP_slash = strchrnul(urlp, ' '); | ||
2199 | /* Is it " HTTP/"? */ | 2195 | /* Is it " HTTP/"? */ |
2200 | if (HTTP_slash[0] && strncmp(HTTP_slash + 1, HTTP_200, 5) == 0) { | 2196 | if (!HTTP_slash || strncmp(HTTP_slash + 1, HTTP_200, 5) != 0) |
2201 | http_major_version = HTTP_slash[6]; | 2197 | send_headers_and_exit(HTTP_BAD_REQUEST); |
2202 | *HTTP_slash++ = '\0'; | 2198 | *HTTP_slash++ = '\0'; |
2203 | } | ||
2204 | 2199 | ||
2205 | /* Copy URL from after "GET "/"POST " to stack-allocated char[] */ | 2200 | /* Copy URL from after "GET "/"POST " to stack-allocated char[] */ |
2206 | urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page)); | 2201 | urlcopy = alloca((HTTP_slash - urlp) + 2 + strlen(index_page)); |
@@ -2216,6 +2211,8 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2216 | Htaccess_Proxy *proxy_entry = find_proxy_entry(urlcopy); | 2211 | Htaccess_Proxy *proxy_entry = find_proxy_entry(urlcopy); |
2217 | 2212 | ||
2218 | if (proxy_entry) { | 2213 | if (proxy_entry) { |
2214 | if (verbose > 1) | ||
2215 | bb_error_msg("proxy:%s", urlcopy); | ||
2219 | lsa = host2sockaddr(proxy_entry->host_port, 80); | 2216 | lsa = host2sockaddr(proxy_entry->host_port, 80); |
2220 | if (!lsa) | 2217 | if (!lsa) |
2221 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); | 2218 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); |
@@ -2233,7 +2230,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2233 | prequest, /* "GET" or "POST" */ | 2230 | prequest, /* "GET" or "POST" */ |
2234 | proxy_entry->url_to, /* "/new/path" */ | 2231 | proxy_entry->url_to, /* "/new/path" */ |
2235 | urlcopy + strlen(proxy_entry->url_from), /* "SFX" */ | 2232 | urlcopy + strlen(proxy_entry->url_from), /* "SFX" */ |
2236 | HTTP_slash /* HTTP/xyz" or "" */ | 2233 | HTTP_slash /* "HTTP/xyz" */ |
2237 | ); | 2234 | ); |
2238 | cgi_io_loop_and_exit(proxy_fd, proxy_fd, /*max POST length:*/ INT_MAX); | 2235 | cgi_io_loop_and_exit(proxy_fd, proxy_fd, /*max POST length:*/ INT_MAX); |
2239 | } | 2236 | } |
@@ -2366,8 +2363,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2366 | #if ENABLE_FEATURE_HTTPD_CGI | 2363 | #if ENABLE_FEATURE_HTTPD_CGI |
2367 | total_headers_len = 0; | 2364 | total_headers_len = 0; |
2368 | #endif | 2365 | #endif |
2369 | if (http_major_version >= '0') { | ||
2370 | /* Request was with "... HTTP/nXXX", and n >= 0 */ | ||
2371 | 2366 | ||
2372 | /* Read until blank line */ | 2367 | /* Read until blank line */ |
2373 | while (1) { | 2368 | while (1) { |
@@ -2484,7 +2479,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2484 | } | 2479 | } |
2485 | #endif | 2480 | #endif |
2486 | } /* while extra header reading */ | 2481 | } /* while extra header reading */ |
2487 | } | ||
2488 | 2482 | ||
2489 | /* We are done reading headers, disable peer timeout */ | 2483 | /* We are done reading headers, disable peer timeout */ |
2490 | alarm(0); | 2484 | alarm(0); |