From 03ca795bd6c163eaed116a129ec4d1a53833700c Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 31 May 2016 17:11:59 -0300 Subject: [PATCH 1/4] fix ipv6 http socket host handling as in RFC2732 --- core/net/http-socket/http-socket.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/net/http-socket/http-socket.c b/core/net/http-socket/http-socket.c index 758c1473e..1e5ebbb27 100644 --- a/core/net/http-socket/http-socket.c +++ b/core/net/http-socket/http-socket.c @@ -412,7 +412,15 @@ event(struct tcp_socket *tcps, void *ptr, tcp_socket_send_str(tcps, " HTTP/1.1\r\n"); tcp_socket_send_str(tcps, "Connection: close\r\n"); tcp_socket_send_str(tcps, "Host: "); + /* If we have IPv6 host, add the '[' and the ']' characters + to the host. As in rfc2732. */ + if (strchr(host, ':')) { + tcp_socket_send_str(tcps, "["); + } tcp_socket_send_str(tcps, host); + if (strchr(host, ':')) { + tcp_socket_send_str(tcps, "]"); + } tcp_socket_send_str(tcps, "\r\n"); if(s->postdata != NULL) { if(s->content_type) { From e657ca40e9ed685aa51f3ff956a7c8263c3bcd3e Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Fri, 3 Jun 2016 12:11:51 -0300 Subject: [PATCH 2/4] return error if host does not fit in host string --- core/net/http-socket/http-socket.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/net/http-socket/http-socket.c b/core/net/http-socket/http-socket.c index 1e5ebbb27..ddcebaec1 100644 --- a/core/net/http-socket/http-socket.c +++ b/core/net/http-socket/http-socket.c @@ -349,6 +349,11 @@ parse_url(const char *url, char *host, uint16_t *portptr, char *path) } } + /* check if host is null terminated */ + if (!memchr(host, 0, MAX_HOSTLEN)) { + return 0; + } + /* Find the port. Default is 80. */ port = 80; if(*urlptr == ':') { From 19e08de0e2d498dc1b8a7fdedffd599420f1d778 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Fri, 3 Jun 2016 12:12:24 -0300 Subject: [PATCH 3/4] use memchr instead of strchr for checking if host is ipv6 --- core/net/http-socket/http-socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/net/http-socket/http-socket.c b/core/net/http-socket/http-socket.c index ddcebaec1..4d78cc276 100644 --- a/core/net/http-socket/http-socket.c +++ b/core/net/http-socket/http-socket.c @@ -419,11 +419,11 @@ event(struct tcp_socket *tcps, void *ptr, tcp_socket_send_str(tcps, "Host: "); /* If we have IPv6 host, add the '[' and the ']' characters to the host. As in rfc2732. */ - if (strchr(host, ':')) { + if (memchr(host, ':', MAX_HOSTLEN)) { tcp_socket_send_str(tcps, "["); } tcp_socket_send_str(tcps, host); - if (strchr(host, ':')) { + if (memchr(host, ':', MAX_HOSTLEN)) { tcp_socket_send_str(tcps, "]"); } tcp_socket_send_str(tcps, "\r\n"); From 47df9c4e6ec6402a2be1bbf11c12ca0e63a0a9fc Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Sat, 4 Jun 2016 16:47:52 -0300 Subject: [PATCH 4/4] code style --- core/net/http-socket/http-socket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/net/http-socket/http-socket.c b/core/net/http-socket/http-socket.c index 4d78cc276..7862790ff 100644 --- a/core/net/http-socket/http-socket.c +++ b/core/net/http-socket/http-socket.c @@ -350,7 +350,7 @@ parse_url(const char *url, char *host, uint16_t *portptr, char *path) } /* check if host is null terminated */ - if (!memchr(host, 0, MAX_HOSTLEN)) { + if(!memchr(host, 0, MAX_HOSTLEN)) { return 0; } @@ -419,11 +419,11 @@ event(struct tcp_socket *tcps, void *ptr, tcp_socket_send_str(tcps, "Host: "); /* If we have IPv6 host, add the '[' and the ']' characters to the host. As in rfc2732. */ - if (memchr(host, ':', MAX_HOSTLEN)) { + if(memchr(host, ':', MAX_HOSTLEN)) { tcp_socket_send_str(tcps, "["); } tcp_socket_send_str(tcps, host); - if (memchr(host, ':', MAX_HOSTLEN)) { + if(memchr(host, ':', MAX_HOSTLEN)) { tcp_socket_send_str(tcps, "]"); } tcp_socket_send_str(tcps, "\r\n");