]> granicus.if.org Git - libevent/commitdiff
http: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr
authorAzat Khuzhin <azat@libevent.org>
Sun, 12 May 2019 12:19:31 +0000 (15:19 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sun, 12 May 2019 15:21:21 +0000 (18:21 +0300)
unixsock peer does not have sun_path initialized.

http.c

diff --git a/http.c b/http.c
index ecb12bbffdf37588ec0d0da98aec3312489a1873..77abd4267d825fe1612d9b4f7bcb895c0603bcea 100644 (file)
--- a/http.c
+++ b/http.c
 #ifndef _WIN32
 #include <sys/socket.h>
 #include <sys/stat.h>
-#else
+#else /* _WIN32 */
 #include <winsock2.h>
 #include <ws2tcpip.h>
+#endif /* _WIN32 */
+
+#ifdef EVENT__HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef EVENT__HAVE_AFUNIX_H
+#include <afunix.h>
 #endif
 
 #include <sys/queue.h>
@@ -78,7 +85,7 @@
 #include <string.h>
 #ifndef _WIN32
 #include <syslog.h>
-#endif
+#endif /* !_WIN32 */
 #include <signal.h>
 #ifdef EVENT__HAVE_UNISTD_H
 #include <unistd.h>
@@ -4421,6 +4428,13 @@ evhttp_get_request_connection(
        char *hostname = NULL, *portname = NULL;
        struct bufferevent* bev = NULL;
 
+#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN
+       if (sa->sa_family == AF_UNIX) {
+               struct sockaddr_un *sun = (struct sockaddr_un *)sa;
+               sun->sun_path[0] = '\0';
+       }
+#endif
+
        name_from_addr(sa, salen, &hostname, &portname);
        if (hostname == NULL || portname == NULL) {
                if (hostname) mm_free(hostname);