diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-16 16:20:12 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-11-16 16:20:12 +0000 |
| commit | c0e6a05b3bc6d2185e7d077f5accccb04eff1b4d (patch) | |
| tree | 12405969e6505bc22b3dd4fb2a7b0b90df29c0da | |
| parent | 4a36653f6e5ba4b0e703f3a741a616c509d50100 (diff) | |
| download | busybox-w32-c0e6a05b3bc6d2185e7d077f5accccb04eff1b4d.tar.gz busybox-w32-c0e6a05b3bc6d2185e7d077f5accccb04eff1b4d.tar.bz2 busybox-w32-c0e6a05b3bc6d2185e7d077f5accccb04eff1b4d.zip | |
httpd:
fix union aliasing bug
symptom: wget of non-existent file gets redirected to /text/html/something
on second and subsequend wget attempts
fix double-free bug
symptom: glibc caught double-free (we didn't NULL config->xxx ptrs after free)
git-svn-id: svn://busybox.net/trunk/busybox@16539 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | networking/httpd.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index e125095f1..c0b740f6f 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
| @@ -143,10 +143,8 @@ typedef struct { | |||
| 143 | #endif | 143 | #endif |
| 144 | unsigned port; /* server initial port and for | 144 | unsigned port; /* server initial port and for |
| 145 | set env REMOTE_PORT */ | 145 | set env REMOTE_PORT */ |
| 146 | union HTTPD_FOUND { | 146 | const char *found_mime_type; |
| 147 | const char *found_mime_type; | 147 | const char *found_moved_temporarily; |
| 148 | const char *found_moved_temporarily; | ||
| 149 | } httpd_found; | ||
| 150 | 148 | ||
| 151 | off_t ContentLength; /* -1 - unknown */ | 149 | off_t ContentLength; /* -1 - unknown */ |
| 152 | time_t last_mod; | 150 | time_t last_mod; |
| @@ -857,7 +855,7 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
| 857 | } | 855 | } |
| 858 | /* error message is HTML */ | 856 | /* error message is HTML */ |
| 859 | mime_type = responseNum == HTTP_OK ? | 857 | mime_type = responseNum == HTTP_OK ? |
| 860 | config->httpd_found.found_mime_type : "text/html"; | 858 | config->found_mime_type : "text/html"; |
| 861 | 859 | ||
| 862 | /* emit the current date */ | 860 | /* emit the current date */ |
| 863 | strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&timer)); | 861 | strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&timer)); |
| @@ -874,7 +872,7 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
| 874 | #endif | 872 | #endif |
| 875 | if (responseNum == HTTP_MOVED_TEMPORARILY) { | 873 | if (responseNum == HTTP_MOVED_TEMPORARILY) { |
| 876 | len += sprintf(buf+len, "Location: %s/%s%s\r\n", | 874 | len += sprintf(buf+len, "Location: %s/%s%s\r\n", |
| 877 | config->httpd_found.found_moved_temporarily, | 875 | config->found_moved_temporarily, |
| 878 | (config->query ? "?" : ""), | 876 | (config->query ? "?" : ""), |
| 879 | (config->query ? config->query : "")); | 877 | (config->query ? config->query : "")); |
| 880 | } | 878 | } |
| @@ -894,7 +892,7 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
| 894 | responseNum, responseString, infoString); | 892 | responseNum, responseString, infoString); |
| 895 | } | 893 | } |
| 896 | #if DEBUG | 894 | #if DEBUG |
| 897 | fprintf(stderr, "Headers: '%s'", buf); | 895 | fprintf(stderr, "headers: '%s'\n", buf); |
| 898 | #endif | 896 | #endif |
| 899 | return full_write(config->accepted_socket, buf, len); | 897 | return full_write(config->accepted_socket, buf, len); |
| 900 | } | 898 | } |
| @@ -1246,14 +1244,14 @@ static int sendFile(const char *url) | |||
| 1246 | break; | 1244 | break; |
| 1247 | } | 1245 | } |
| 1248 | /* also, if not found, set default as "application/octet-stream"; */ | 1246 | /* also, if not found, set default as "application/octet-stream"; */ |
| 1249 | config->httpd_found.found_mime_type = *(table+1); | 1247 | config->found_mime_type = table[1]; |
| 1250 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES | 1248 | #if ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES |
| 1251 | if (suffix) { | 1249 | if (suffix) { |
| 1252 | Htaccess * cur; | 1250 | Htaccess * cur; |
| 1253 | 1251 | ||
| 1254 | for (cur = config->mime_a; cur; cur = cur->next) { | 1252 | for (cur = config->mime_a; cur; cur = cur->next) { |
| 1255 | if (strcmp(cur->before_colon, suffix) == 0) { | 1253 | if (strcmp(cur->before_colon, suffix) == 0) { |
| 1256 | config->httpd_found.found_mime_type = cur->after_colon; | 1254 | config->found_mime_type = cur->after_colon; |
| 1257 | break; | 1255 | break; |
| 1258 | } | 1256 | } |
| 1259 | } | 1257 | } |
| @@ -1261,8 +1259,8 @@ static int sendFile(const char *url) | |||
| 1261 | #endif /* CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */ | 1259 | #endif /* CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES */ |
| 1262 | 1260 | ||
| 1263 | #if DEBUG | 1261 | #if DEBUG |
| 1264 | fprintf(stderr, "Sending file '%s' Content-type: %s\n", | 1262 | fprintf(stderr, "sending file '%s' content-type: %s\n", |
| 1265 | url, config->httpd_found.found_mime_type); | 1263 | url, config->found_mime_type); |
| 1266 | #endif | 1264 | #endif |
| 1267 | 1265 | ||
| 1268 | f = open(url, O_RDONLY); | 1266 | f = open(url, O_RDONLY); |
| @@ -1278,7 +1276,7 @@ static int sendFile(const char *url) | |||
| 1278 | close(f); | 1276 | close(f); |
| 1279 | } else { | 1277 | } else { |
| 1280 | #if DEBUG | 1278 | #if DEBUG |
| 1281 | bb_perror_msg("unable to open '%s'", url); | 1279 | bb_perror_msg("cannot open '%s'", url); |
| 1282 | #endif | 1280 | #endif |
| 1283 | sendHeaders(HTTP_NOT_FOUND); | 1281 | sendHeaders(HTTP_NOT_FOUND); |
| 1284 | } | 1282 | } |
| @@ -1434,7 +1432,7 @@ static void handleIncoming(void) | |||
| 1434 | int ip_allowed; | 1432 | int ip_allowed; |
| 1435 | #if ENABLE_FEATURE_HTTPD_CGI | 1433 | #if ENABLE_FEATURE_HTTPD_CGI |
| 1436 | const char *prequest = request_GET; | 1434 | const char *prequest = request_GET; |
| 1437 | long length=0; | 1435 | long length = 0; |
| 1438 | char *cookie = 0; | 1436 | char *cookie = 0; |
| 1439 | char *content_type = 0; | 1437 | char *content_type = 0; |
| 1440 | #endif | 1438 | #endif |
| @@ -1538,7 +1536,7 @@ BAD_REQUEST: | |||
| 1538 | /* If URL is directory, adding '/' */ | 1536 | /* If URL is directory, adding '/' */ |
| 1539 | if (test[-1] != '/') { | 1537 | if (test[-1] != '/') { |
| 1540 | if (is_directory(url + 1, 1, &sb)) { | 1538 | if (is_directory(url + 1, 1, &sb)) { |
| 1541 | config->httpd_found.found_moved_temporarily = url; | 1539 | config->found_moved_temporarily = url; |
| 1542 | } | 1540 | } |
| 1543 | } | 1541 | } |
| 1544 | #if DEBUG | 1542 | #if DEBUG |
| @@ -1628,12 +1626,10 @@ FORBIDDEN: /* protect listing /cgi-bin */ | |||
| 1628 | } | 1626 | } |
| 1629 | #endif | 1627 | #endif |
| 1630 | 1628 | ||
| 1631 | if (config->httpd_found.found_moved_temporarily) { | 1629 | if (config->found_moved_temporarily) { |
| 1632 | sendHeaders(HTTP_MOVED_TEMPORARILY); | 1630 | sendHeaders(HTTP_MOVED_TEMPORARILY); |
| 1633 | #if DEBUG | ||
| 1634 | /* clear unforked memory flag */ | 1631 | /* clear unforked memory flag */ |
| 1635 | config->httpd_found.found_moved_temporarily = NULL; | 1632 | config->found_moved_temporarily = NULL; |
| 1636 | #endif | ||
| 1637 | break; | 1633 | break; |
| 1638 | } | 1634 | } |
| 1639 | 1635 | ||
| @@ -1668,14 +1664,14 @@ FORBIDDEN: /* protect listing /cgi-bin */ | |||
| 1668 | } while (0); | 1664 | } while (0); |
| 1669 | 1665 | ||
| 1670 | # if DEBUG | 1666 | # if DEBUG |
| 1671 | fprintf(stderr, "closing socket\n"); | 1667 | fprintf(stderr, "closing socket\n\n"); |
| 1672 | # endif | 1668 | # endif |
| 1673 | # if ENABLE_FEATURE_HTTPD_CGI | 1669 | # if ENABLE_FEATURE_HTTPD_CGI |
| 1674 | free(cookie); | 1670 | free(cookie); |
| 1675 | free(content_type); | 1671 | free(content_type); |
| 1676 | free(config->referer); | 1672 | free(config->referer); config->referer = NULL; |
| 1677 | # if ENABLE_FEATURE_HTTPD_BASIC_AUTH | 1673 | # if ENABLE_FEATURE_HTTPD_BASIC_AUTH |
| 1678 | free(config->remoteuser); | 1674 | free(config->remoteuser); config->remoteuser = NULL; |
| 1679 | # endif | 1675 | # endif |
| 1680 | # endif | 1676 | # endif |
| 1681 | shutdown(config->accepted_socket, SHUT_WR); | 1677 | shutdown(config->accepted_socket, SHUT_WR); |
| @@ -1733,7 +1729,6 @@ static int miniHttpd(int server) | |||
| 1733 | s = accept(server, (struct sockaddr *)&fromAddr, &fromAddrLen); | 1729 | s = accept(server, (struct sockaddr *)&fromAddr, &fromAddrLen); |
| 1734 | if (s < 0) | 1730 | if (s < 0) |
| 1735 | continue; | 1731 | continue; |
| 1736 | |||
| 1737 | config->accepted_socket = s; | 1732 | config->accepted_socket = s; |
| 1738 | config->rmt_ip = ntohl(fromAddr.sin_addr.s_addr); | 1733 | config->rmt_ip = ntohl(fromAddr.sin_addr.s_addr); |
| 1739 | #if ENABLE_FEATURE_HTTPD_CGI || DEBUG | 1734 | #if ENABLE_FEATURE_HTTPD_CGI || DEBUG |
