Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/httpd.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/httpd.c
r3232 r3621 126 126 127 127 #include "libbb.h" 128 #include "common_bufsiz.h" 128 129 #if ENABLE_PAM 129 130 /* PAM may include <locale.h>. We may need to undefine bbox's stub define: */ … … 134 135 # include <security/pam_misc.h> 135 136 #endif 136 #if ENABLE_FEATURE_ HTTPD_USE_SENDFILE137 #if ENABLE_FEATURE_USE_SENDFILE 137 138 # include <sys/sendfile.h> 138 139 #endif … … 308 309 #endif 309 310 char *iobuf; /* [IOBUF_SIZE] */ 310 #define hdr_buf bb_common_bufsiz1 311 #define hdr_buf bb_common_bufsiz1 312 #define sizeof_hdr_buf COMMON_BUFSIZE 311 313 char *hdr_ptr; 312 314 int hdr_cnt; … … 369 371 #endif 370 372 #define INIT_G() do { \ 373 setup_common_bufsiz(); \ 371 374 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 372 375 IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ … … 698 701 } 699 702 *host_port++ = '\0'; 700 if ( strncmp(host_port, "http://", 7) == 0)703 if (is_prefixed_with(host_port, "http://")) 701 704 host_port += 7; 702 705 if (*host_port == '\0') { … … 968 971 #endif 969 972 if (responseNum == HTTP_MOVED_TEMPORARILY) { 970 len += sprintf(iobuf + len, "Location: %s/%s%s\r\n", 973 /* Responding to "GET /dir" with 974 * "HTTP/1.0 302 Found" "Location: /dir/" 975 * - IOW, asking them to repeat with a slash. 976 * Here, overflow IS possible, can't use sprintf: 977 * mkdir test 978 * python -c 'print("get /test?" + ("x" * 8192))' | busybox httpd -i -h . 979 */ 980 len += snprintf(iobuf + len, IOBUF_SIZE-3 - len, 981 "Location: %s/%s%s\r\n", 971 982 found_moved_temporarily, 972 983 (g_query ? "?" : ""), 973 984 (g_query ? g_query : "")); 985 if (len > IOBUF_SIZE-3) 986 len = IOBUF_SIZE-3; 974 987 } 975 988 976 989 #if ENABLE_FEATURE_HTTPD_ERROR_PAGES 977 990 if (error_page && access(error_page, R_OK) == 0) { 978 strcat(iobuf, "\r\n");979 len += 2;980 981 if (DEBUG)991 iobuf[len++] = '\r'; 992 iobuf[len++] = '\n'; 993 if (DEBUG) { 994 iobuf[len] = '\0'; 982 995 fprintf(stderr, "headers: '%s'\n", iobuf); 996 } 983 997 full_write(STDOUT_FILENO, iobuf, len); 984 998 if (DEBUG) … … 1022 1036 responseNum, responseString, infoString); 1023 1037 } 1024 if (DEBUG) 1038 if (DEBUG) { 1039 iobuf[len] = '\0'; 1025 1040 fprintf(stderr, "headers: '%s'\n", iobuf); 1041 } 1026 1042 if (full_write(STDOUT_FILENO, iobuf, len) != len) { 1027 1043 if (verbose > 1) … … 1054 1070 while (1) { 1055 1071 if (hdr_cnt <= 0) { 1056 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof (hdr_buf));1072 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf); 1057 1073 if (hdr_cnt <= 0) 1058 1074 break; … … 1105 1121 /* NB: breaking out of this loop jumps to log_and_exit() */ 1106 1122 out_cnt = 0; 1123 pfd[FROM_CGI].fd = fromCgi_rd; 1124 pfd[FROM_CGI].events = POLLIN; 1125 pfd[TO_CGI].fd = toCgi_wr; 1107 1126 while (1) { 1108 memset(pfd, 0, sizeof(pfd)); 1109 1110 pfd[FROM_CGI].fd = fromCgi_rd; 1111 pfd[FROM_CGI].events = POLLIN; 1112 1113 if (toCgi_wr) { 1114 pfd[TO_CGI].fd = toCgi_wr; 1115 if (hdr_cnt > 0) { 1116 pfd[TO_CGI].events = POLLOUT; 1117 } else if (post_len > 0) { 1118 pfd[0].events = POLLIN; 1127 /* Note: even pfd[0].events == 0 won't prevent 1128 * revents == POLLHUP|POLLERR reports from closed stdin. 1129 * Setting fd to -1 works: */ 1130 pfd[0].fd = -1; 1131 pfd[0].events = POLLIN; 1132 pfd[0].revents = 0; /* probably not needed, paranoia */ 1133 1134 /* We always poll this fd, thus kernel always sets revents: */ 1135 /*pfd[FROM_CGI].events = POLLIN; - moved out of loop */ 1136 /*pfd[FROM_CGI].revents = 0; - not needed */ 1137 1138 /* gcc-4.8.0 still doesnt fill two shorts with one insn :( */ 1139 /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47059 */ 1140 /* hopefully one day it will... */ 1141 pfd[TO_CGI].events = POLLOUT; 1142 pfd[TO_CGI].revents = 0; /* needed! */ 1143 1144 if (toCgi_wr && hdr_cnt <= 0) { 1145 if (post_len > 0) { 1146 /* Expect more POST data from network */ 1147 pfd[0].fd = 0; 1119 1148 } else { 1120 1149 /* post_len <= 0 && hdr_cnt <= 0: … … 1128 1157 1129 1158 /* Now wait on the set of sockets */ 1130 count = safe_poll(pfd, toCgi_wr? TO_CGI+1 : FROM_CGI+1, -1);1159 count = safe_poll(pfd, hdr_cnt > 0 ? TO_CGI+1 : FROM_CGI+1, -1); 1131 1160 if (count <= 0) { 1132 1161 #if 0 … … 1145 1174 1146 1175 if (pfd[TO_CGI].revents) { 1147 /* hdr_cnt > 0 here due to the way p fd[TO_CGI].events set*/1176 /* hdr_cnt > 0 here due to the way poll() called */ 1148 1177 /* Have data from peer and can write to CGI */ 1149 1178 count = safe_write(toCgi_wr, hdr_ptr, hdr_cnt); … … 1166 1195 * and there *is* data to read from the peer 1167 1196 * (POSTDATA) */ 1168 //count = post_len > (int)sizeof (hdr_buf) ? (int)sizeof(hdr_buf): post_len;1197 //count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len; 1169 1198 //count = safe_read(STDIN_FILENO, hdr_buf, count); 1170 count = safe_read(STDIN_FILENO, hdr_buf, sizeof (hdr_buf));1199 count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf); 1171 1200 if (count > 0) { 1172 1201 hdr_cnt = count; … … 1210 1239 count = 0; 1211 1240 /* "Status" header format is: "Status: 302 Redirected\r\n" */ 1212 if (out_cnt >= 8 && memcmp(rbuf, "Status: ", 8) == 0) {1241 if (out_cnt >= 7 && memcmp(rbuf, "Status:", 7) == 0) { 1213 1242 /* send "HTTP/1.0 " */ 1214 1243 if (full_write(STDOUT_FILENO, HTTP_200, 9) != 9) 1215 1244 break; 1216 rbuf += 8; /* skip "Status:" */1217 count = out_cnt - 8;1245 rbuf += 7; /* skip "Status:" */ 1246 count = out_cnt - 7; 1218 1247 out_cnt = -1; /* buffering off */ 1219 1248 } else if (out_cnt >= 4) { … … 1612 1641 if (what & SEND_HEADERS) 1613 1642 send_headers(HTTP_OK); 1614 #if ENABLE_FEATURE_ HTTPD_USE_SENDFILE1643 #if ENABLE_FEATURE_USE_SENDFILE 1615 1644 { 1616 1645 off_t offset = range_start; … … 1642 1671 } 1643 1672 if (count < 0) { 1644 IF_FEATURE_ HTTPD_USE_SENDFILE(fin:)1673 IF_FEATURE_USE_SENDFILE(fin:) 1645 1674 if (verbose > 1) 1646 1675 bb_perror_msg("error"); … … 1710 1739 break; 1711 1740 case PAM_ERROR_MSG: 1712 1713 1741 case PAM_TEXT_INFO: 1742 s = ""; 1714 1743 break; 1715 1744 default: … … 1882 1911 Htaccess_Proxy *p; 1883 1912 for (p = proxy; p; p = p->next) { 1884 if ( strncmp(url, p->url_from, strlen(p->url_from)) == 0)1913 if (is_prefixed_with(url, p->url_from)) 1885 1914 return p; 1886 1915 } … … 1965 1994 1966 1995 /* Determine type of request (GET/POST) */ 1967 urlp = strpbrk(iobuf, " \t"); 1996 // rfc2616: method and URI is separated by exactly one space 1997 //urlp = strpbrk(iobuf, " \t"); - no, tab isn't allowed 1998 urlp = strchr(iobuf, ' '); 1968 1999 if (urlp == NULL) 1969 2000 send_headers_and_exit(HTTP_BAD_REQUEST); … … 1983 2014 send_headers_and_exit(HTTP_NOT_IMPLEMENTED); 1984 2015 #endif 1985 urlp = skip_whitespace(urlp); 2016 // rfc2616: method and URI is separated by exactly one space 2017 //urlp = skip_whitespace(urlp); - should not be necessary 1986 2018 if (urlp[0] != '/') 1987 2019 send_headers_and_exit(HTTP_BAD_REQUEST); … … 2168 2200 /* We know only bytes=NNN-[MMM] */ 2169 2201 char *s = skip_whitespace(iobuf + sizeof("Range:")-1); 2170 if ( strncmp(s, "bytes=", 6) == 0) {2202 if (is_prefixed_with(s, "bytes=") == 0) { 2171 2203 s += sizeof("bytes=")-1; 2172 2204 range_start = BB_STRTOOFF(s, &s, 10); … … 2254 2286 2255 2287 #if ENABLE_FEATURE_HTTPD_CGI 2256 if ( strncmp(tptr, "cgi-bin/", 8) == 0) {2288 if (is_prefixed_with(tptr, "cgi-bin/")) { 2257 2289 if (tptr[8] == '\0') { 2258 2290 /* protect listing "cgi-bin/" */ … … 2337 2369 2338 2370 /* set the KEEPALIVE option to cull dead connections */ 2339 setsockopt (n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));2371 setsockopt_keepalive(n); 2340 2372 2341 2373 if (fork() == 0) { … … 2380 2412 2381 2413 /* set the KEEPALIVE option to cull dead connections */ 2382 setsockopt (n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));2414 setsockopt_keepalive(n); 2383 2415 2384 2416 if (vfork() == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.