summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2019-04-14 20:46:57 +0200
committerDenys Vlasenko2019-04-14 20:46:57 +0200
commit02d650e15919e48fe031308c77c041159c0e3631 (patch)
tree05da096c443553dd7845955901240cc1a7794f8e
parent51792e126bddaabf572132f1e0d4ed9bfd324c58 (diff)
downloadbusybox-02d650e15919e48fe031308c77c041159c0e3631.zip
busybox-02d650e15919e48fe031308c77c041159c0e3631.tar.gz
httpd: fix proxy headers passing - full_write() instead of write()
function old new delta handle_incoming_and_exit 2763 2752 -11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/httpd.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index f713f69..c486197 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2271,15 +2271,20 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
bb_error_msg("header: '%s'", iobuf);
#if ENABLE_FEATURE_HTTPD_PROXY
- /* We need 2 more bytes for yet another "\r\n" -
- * see near fdprintf(proxy_fd...) further below */
- if (proxy_entry && (header_ptr - header_buf) < IOBUF_SIZE - 4) {
- int len = strnlen(iobuf, IOBUF_SIZE - (header_ptr - header_buf) - 4);
- memcpy(header_ptr, iobuf, len);
- header_ptr += len;
- header_ptr[0] = '\r';
- header_ptr[1] = '\n';
- header_ptr += 2;
+ if (proxy_entry) {
+ /* Why 4, not 2?
+ * We need 2 more bytes for yet another "\r\n" -
+ * see near fdprintf(proxy_fd...) further below.
+ */
+ int maxlen = (IOBUF_SIZE-4) - (int)(header_ptr - header_buf);
+ if (maxlen > 0) {
+ int len = strnlen(iobuf, maxlen);
+ memcpy(header_ptr, iobuf, len);
+ header_ptr += len;
+ header_ptr[0] = '\r';
+ header_ptr[1] = '\n';
+ header_ptr += 2;
+ }
}
#endif
@@ -2401,7 +2406,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
}
#if ENABLE_FEATURE_HTTPD_PROXY
- if (proxy_entry != NULL) {
+ if (proxy_entry) {
int proxy_fd;
len_and_sockaddr *lsa;
@@ -2423,7 +2428,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
header_ptr[0] = '\r';
header_ptr[1] = '\n';
header_ptr += 2;
- write(proxy_fd, header_buf, header_ptr - header_buf);
+ full_write(proxy_fd, header_buf, header_ptr - header_buf);
free(header_buf); /* on the order of 8k, free it */
cgi_io_loop_and_exit(proxy_fd, proxy_fd, length);
}