From: Azat Khuzhin <azat@libevent.org>
Date: Sun, 12 May 2019 12:19:31 +0000 (+0300)
Subject: http: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad51a3c1bac21e14591aafe3cc10292a6b48b5ad;p=libevent

http: avoid use of uninitialized value for AF_UNIX/AF_LOCAL sockaddr

unixsock peer does not have sun_path initialized.
---

diff --git a/http.c b/http.c
index ecb12bbf..77abd426 100644
--- a/http.c
+++ b/http.c
@@ -51,9 +51,16 @@
 #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);