diff options
author | Laurent Bercot <ska-dietlibc@skarnet.org> | 2017-01-06 22:03:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-08 15:14:38 +0100 |
commit | 0ef478f01bb3d42f6776f58fb5891e1430af8799 (patch) | |
tree | d40e5517fc23296473e4a3ad95f7f04386e78ce4 | |
parent | 4d06b314532f7f52a9d8a5d6b7dcafaf00ff1334 (diff) | |
download | busybox-w32-0ef478f01bb3d42f6776f58fb5891e1430af8799.tar.gz busybox-w32-0ef478f01bb3d42f6776f58fb5891e1430af8799.tar.bz2 busybox-w32-0ef478f01bb3d42f6776f58fb5891e1430af8799.zip |
httpd: fix address family for reverse proxy client socket
When httpd proxies a request to another server, it first creates
an AF_INET socket, then resolves the server name to a sockaddr,
then connects to it. This fails if the server name resolves to
an IPv6 address.
This patch ensures that the socket is created with the correct
address family (AF_INET6 if the server resolves to an IPv6 address
and AF_INET otherwise).
Signed-off-by: Laurent Bercot <ska-dietlibc@skarnet.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/httpd.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index d301d598d..cfcd2a06e 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -2396,12 +2396,12 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2396 | int proxy_fd; | 2396 | int proxy_fd; |
2397 | len_and_sockaddr *lsa; | 2397 | len_and_sockaddr *lsa; |
2398 | 2398 | ||
2399 | proxy_fd = socket(AF_INET, SOCK_STREAM, 0); | ||
2400 | if (proxy_fd < 0) | ||
2401 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); | ||
2402 | lsa = host2sockaddr(proxy_entry->host_port, 80); | 2399 | lsa = host2sockaddr(proxy_entry->host_port, 80); |
2403 | if (lsa == NULL) | 2400 | if (lsa == NULL) |
2404 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); | 2401 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); |
2402 | proxy_fd = socket(lsa->u.sa.sa_family, SOCK_STREAM, 0); | ||
2403 | if (proxy_fd < 0) | ||
2404 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); | ||
2405 | if (connect(proxy_fd, &lsa->u.sa, lsa->len) < 0) | 2405 | if (connect(proxy_fd, &lsa->u.sa, lsa->len) < 0) |
2406 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); | 2406 | send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR); |
2407 | fdprintf(proxy_fd, "%s %s%s%s%s HTTP/%c.%c\r\n", | 2407 | fdprintf(proxy_fd, "%s %s%s%s%s HTTP/%c.%c\r\n", |