diff --git a/core/net/http-socket/http-socket.c b/core/net/http-socket/http-socket.c index 3495b597b..b08605213 100644 --- a/core/net/http-socket/http-socket.c +++ b/core/net/http-socket/http-socket.c @@ -350,6 +350,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 == ':') { @@ -413,7 +418,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(memchr(host, ':', MAX_HOSTLEN)) { + tcp_socket_send_str(tcps, "["); + } tcp_socket_send_str(tcps, host); + if(memchr(host, ':', MAX_HOSTLEN)) { + tcp_socket_send_str(tcps, "]"); + } tcp_socket_send_str(tcps, "\r\n"); if(s->postdata != NULL) { if(s->content_type) {