From 54180552e4e63dc1c66304f2ed5fb9ff483203b5 Mon Sep 17 00:00:00 2001 From: fanc <cf2008chenfan@163.com> Date: Fri, 15 Feb 2019 16:42:17 +0800 Subject: [PATCH] client: confirm sin_zero actual size for platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in some platform, the size of sa46.sa4.sin_zero is not 8, but 6, so use 8 will cause coredump. --- lib/roles/http/client/client-handshake.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 6b4e98f3..d3cacb8c 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -264,9 +264,10 @@ create_new_conn: * to whatever we decided to connect to */ - lwsl_info("%s: %p: address %s\n", __func__, wsi, ads); + lwsl_info("%s: %p: address %s\n", __func__, wsi, ads); - n = lws_getaddrinfo46(wsi, ads, &result); + n = lws_getaddrinfo46(wsi, ads, &result); + memset(&sa46, 0, sizeof(sa46)); #ifdef LWS_WITH_IPV6 if (wsi->ipv6) { @@ -282,8 +283,6 @@ create_new_conn: sa6 = ((struct sockaddr_in6 *)result->ai_addr); - memset(&sa46, 0, sizeof(sa46)); - sa46.sa6.sin6_family = AF_INET6; switch (result->ai_family) { case AF_INET: @@ -363,7 +362,7 @@ create_new_conn: sa46.sa4.sin_family = AF_INET; sa46.sa4.sin_addr = *((struct in_addr *)p); - bzero(&sa46.sa4.sin_zero, 8); + bzero(&sa46.sa4.sin_zero, sizeof(sa46.sa4.sin_zero)); } if (result) -- GitLab