aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-04-16 13:18:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-16 13:18:12 +0200
commit62ba9e5ac3f158eb36b365af43f8d7d680710963 (patch)
tree9d784a3ad9e39d36df7ad015e1b88bb682f3c166
parent44f5b6a1cb66ee0a6d253de306b167baf33d02c9 (diff)
downloadbusybox-w32-62ba9e5ac3f158eb36b365af43f8d7d680710963.tar.gz
busybox-w32-62ba9e5ac3f158eb36b365af43f8d7d680710963.tar.bz2
busybox-w32-62ba9e5ac3f158eb36b365af43f8d7d680710963.zip
httpd: make rmt_ip variable local
function old new delta handle_incoming_and_exit 2385 2398 +13 if_ip_denied_send_HTTP_FORBIDDEN_and_exit 51 54 +3 get_line 110 106 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-4) Total: 12 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index d29335c3c..7cbf9afef 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -407,7 +407,6 @@ struct globals {
407 /* client can handle gzip / we are going to send gzip */ 407 /* client can handle gzip / we are going to send gzip */
408 smallint content_gzip; 408 smallint content_gzip;
409#endif 409#endif
410 unsigned rmt_ip; /* used for IP-based allow/deny rules */
411 time_t last_mod; 410 time_t last_mod;
412 char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */ 411 char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */
413 const char *bind_addr_or_port; 412 const char *bind_addr_or_port;
@@ -458,7 +457,6 @@ struct globals {
458#else 457#else
459# define content_gzip 0 458# define content_gzip 0
460#endif 459#endif
461#define rmt_ip (G.rmt_ip )
462#define bind_addr_or_port (G.bind_addr_or_port) 460#define bind_addr_or_port (G.bind_addr_or_port)
463#define g_query (G.g_query ) 461#define g_query (G.g_query )
464#define opt_c_configFile (G.opt_c_configFile ) 462#define opt_c_configFile (G.opt_c_configFile )
@@ -1207,9 +1205,9 @@ static void send_headers_and_exit(int responseNum)
1207 * ('\r' and '\n' are not counted). 1205 * ('\r' and '\n' are not counted).
1208 * Data is returned in iobuf. 1206 * Data is returned in iobuf.
1209 */ 1207 */
1210static int get_line(void) 1208static unsigned get_line(void)
1211{ 1209{
1212 int count; 1210 unsigned count;
1213 char c; 1211 char c;
1214 1212
1215 alarm(HEADER_READ_TIMEOUT); 1213 alarm(HEADER_READ_TIMEOUT);
@@ -1807,7 +1805,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what)
1807 log_and_exit(); 1805 log_and_exit();
1808} 1806}
1809 1807
1810static void if_ip_denied_send_HTTP_FORBIDDEN_and_exit(void) 1808static void if_ip_denied_send_HTTP_FORBIDDEN_and_exit(unsigned remote_ip)
1811{ 1809{
1812 Htaccess_IP *cur; 1810 Htaccess_IP *cur;
1813 1811
@@ -1826,7 +1824,7 @@ static void if_ip_denied_send_HTTP_FORBIDDEN_and_exit(void)
1826 (unsigned char)(cur->mask) 1824 (unsigned char)(cur->mask)
1827 ); 1825 );
1828#endif 1826#endif
1829 if ((rmt_ip & cur->mask) == cur->ip) { 1827 if ((remote_ip & cur->mask) == cur->ip) {
1830 if (cur->allow_deny == 'A') 1828 if (cur->allow_deny == 'A')
1831 return; 1829 return;
1832 send_headers_and_exit(HTTP_FORBIDDEN); 1830 send_headers_and_exit(HTTP_FORBIDDEN);
@@ -2071,7 +2069,10 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2071 char *urlcopy; 2069 char *urlcopy;
2072 char *urlp; 2070 char *urlp;
2073 char *tptr; 2071 char *tptr;
2074 unsigned header_len; 2072 unsigned remote_ip;
2073#if ENABLE_FEATURE_HTTPD_CGI
2074 unsigned total_headers_len;
2075#endif
2075#if ENABLE_FEATURE_HTTPD_CGI 2076#if ENABLE_FEATURE_HTTPD_CGI
2076 static const char request_HEAD[] ALIGN1 = "HEAD"; 2077 static const char request_HEAD[] ALIGN1 = "HEAD";
2077 const char *prequest; 2078 const char *prequest;
@@ -2091,16 +2092,16 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2091 * (IOW, server process doesn't need to waste 8k) */ 2092 * (IOW, server process doesn't need to waste 8k) */
2092 iobuf = xmalloc(IOBUF_SIZE); 2093 iobuf = xmalloc(IOBUF_SIZE);
2093 2094
2094 rmt_ip = 0; 2095 remote_ip = 0;
2095 if (fromAddr->u.sa.sa_family == AF_INET) { 2096 if (fromAddr->u.sa.sa_family == AF_INET) {
2096 rmt_ip = ntohl(fromAddr->u.sin.sin_addr.s_addr); 2097 remote_ip = ntohl(fromAddr->u.sin.sin_addr.s_addr);
2097 } 2098 }
2098#if ENABLE_FEATURE_IPV6 2099#if ENABLE_FEATURE_IPV6
2099 if (fromAddr->u.sa.sa_family == AF_INET6 2100 if (fromAddr->u.sa.sa_family == AF_INET6
2100 && fromAddr->u.sin6.sin6_addr.s6_addr32[0] == 0 2101 && fromAddr->u.sin6.sin6_addr.s6_addr32[0] == 0
2101 && fromAddr->u.sin6.sin6_addr.s6_addr32[1] == 0 2102 && fromAddr->u.sin6.sin6_addr.s6_addr32[1] == 0
2102 && ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[2]) == 0xffff) 2103 && ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[2]) == 0xffff)
2103 rmt_ip = ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[3]); 2104 remote_ip = ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[3]);
2104#endif 2105#endif
2105 if (ENABLE_FEATURE_HTTPD_CGI || DEBUG || verbose) { 2106 if (ENABLE_FEATURE_HTTPD_CGI || DEBUG || verbose) {
2106 /* NB: can be NULL (user runs httpd -i by hand?) */ 2107 /* NB: can be NULL (user runs httpd -i by hand?) */
@@ -2113,7 +2114,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2113 if (verbose > 2) 2114 if (verbose > 2)
2114 bb_error_msg("connected"); 2115 bb_error_msg("connected");
2115 } 2116 }
2116 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(); 2117 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip);
2117 2118
2118 /* Install timeout handler. get_line() needs it. */ 2119 /* Install timeout handler. get_line() needs it. */
2119 signal(SIGALRM, send_REQUEST_TIMEOUT_and_exit); 2120 signal(SIGALRM, send_REQUEST_TIMEOUT_and_exit);
@@ -2268,7 +2269,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2268 if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) { 2269 if (is_directory(urlcopy + 1, /*followlinks:*/ 1)) {
2269 /* may have subdir config */ 2270 /* may have subdir config */
2270 parse_conf(urlcopy + 1, SUBDIR_PARSE); 2271 parse_conf(urlcopy + 1, SUBDIR_PARSE);
2271 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(); 2272 if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip);
2272 } 2273 }
2273 *tptr = '/'; 2274 *tptr = '/';
2274 } 2275 }
@@ -2324,21 +2325,25 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2324#endif 2325#endif
2325 urlp[0] = '\0'; 2326 urlp[0] = '\0';
2326 2327
2327 header_len = 0; 2328#if ENABLE_FEATURE_HTTPD_CGI
2329 total_headers_len = 0;
2330#endif
2328 if (http_major_version >= '0') { 2331 if (http_major_version >= '0') {
2329 /* Request was with "... HTTP/nXXX", and n >= 0 */ 2332 /* Request was with "... HTTP/nXXX", and n >= 0 */
2330 2333
2331 /* Read until blank line */ 2334 /* Read until blank line */
2332 while (1) { 2335 while (1) {
2333 int iobuf_len = get_line(); 2336 unsigned iobuf_len = get_line();
2334 if (!iobuf_len) 2337 if (!iobuf_len)
2335 break; /* EOF or error or empty line */ 2338 break; /* EOF or error or empty line */
2336 header_len += iobuf_len + 2; 2339#if ENABLE_FEATURE_HTTPD_CGI
2337 if (header_len >= MAX_HTTP_HEADERS_SIZE) 2340 /* Prevent unlimited growth of HTTP_xyz envvars */
2341 total_headers_len += iobuf_len;
2342 if (total_headers_len >= MAX_HTTP_HEADERS_SIZE)
2338 send_headers_and_exit(HTTP_ENTITY_TOO_LARGE); 2343 send_headers_and_exit(HTTP_ENTITY_TOO_LARGE);
2344#endif
2339 if (DEBUG) 2345 if (DEBUG)
2340 bb_error_msg("header: '%s'", iobuf); 2346 bb_error_msg("header: '%s'", iobuf);
2341
2342#if ENABLE_FEATURE_HTTPD_CGI || ENABLE_FEATURE_HTTPD_PROXY 2347#if ENABLE_FEATURE_HTTPD_CGI || ENABLE_FEATURE_HTTPD_PROXY
2343 /* Try and do our best to parse more lines */ 2348 /* Try and do our best to parse more lines */
2344 if ((STRNCASECMP(iobuf, "Content-Length:") == 0)) { 2349 if ((STRNCASECMP(iobuf, "Content-Length:") == 0)) {