From: Junyeon LEE Date: Mon, 17 Apr 2017 04:28:08 +0000 (+0900) Subject: netutils/websocket: fixes wrong buffer size of inet_ntop X-Git-Tag: 1.1_Public_Release~597^2~147 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cae383e66b25682a71c2b0896bdf0661ecdbed27;p=rtos%2Ftinyara.git netutils/websocket: fixes wrong buffer size of inet_ntop This commit fixes wrong input size in inet_ntop and adds libc dependency. Change-Id: Ic9b567832b202209c1bb8aa9f5aef2c3e23cae4b Signed-off-by: Junyeon LEE --- diff --git a/apps/netutils/websocket/websocket.c b/apps/netutils/websocket/websocket.c index 7d970f4..23ec1f0 100644 --- a/apps/netutils/websocket/websocket.c +++ b/apps/netutils/websocket/websocket.c @@ -22,6 +22,8 @@ * Included Files ****************************************************************************/ +#include + #include #include #include @@ -348,7 +350,7 @@ int connect_socket(websocket_t *client, const char *host, const char *port) socklen_t addrlen; struct sockaddr_in serveraddr; -#ifdef CONFIG_NET_LOOPBACK +#ifdef CONFIG_LIBC_NETDB struct hostent *he = NULL; char ip_str[INET6_ADDRSTRLEN]; @@ -358,9 +360,11 @@ int connect_socket(websocket_t *client, const char *host, const char *port) WEBSOCKET_DEBUG("failed to resolve hostname\n"); return WEBSOCKET_CONNECT_ERROR; } - inet_ntop(he->h_addrtype, he->h_addr, ip_str, he->h_length); + if (inet_ntop(he->h_addrtype, he->h_addr, ip_str, sizeof(ip_str)) == NULL) { + WEBSOCKET_DEBUG("inet_ntop failed (errno=%d)\n", errno); + return WEBSOCKET_CONNECT_ERROR; + } #endif - fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { WEBSOCKET_DEBUG("fail to open socket\n"); @@ -369,7 +373,7 @@ int connect_socket(websocket_t *client, const char *host, const char *port) serveraddr.sin_family = AF_INET; serveraddr.sin_port = htons(atoi(port)); -#ifdef CONFIG_NET_LOOPBACK +#ifdef CONFIG_LIBC_NETDB serveraddr.sin_addr.s_addr = inet_addr(ip_str); #else serveraddr.sin_addr.s_addr = inet_addr(host);