[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 191/220: Curl_addr2string: take an addrlen argument
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 191/220: Curl_addr2string: take an addrlen argument too |
Date: |
Thu, 12 Sep 2019 17:29:11 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 84ced9389e1a7f576812e0675b37056331c4dbcd
Author: Daniel Stenberg <address@hidden>
AuthorDate: Fri Aug 30 11:29:55 2019 +0200
Curl_addr2string: take an addrlen argument too
This allows the function to figure out if a unix domain socket has a
file name or not associated with it! When a socket is created with
socketpair(), as done in the fuzzer testing, the path struct member is
uninitialized and must not be accessed.
Bug: https://crbug.com/oss-fuzz/16699
Closes #4283
---
lib/connect.c | 30 +++++++++++++++++++-----------
lib/connect.h | 3 ++-
lib/vquic/ngtcp2.c | 3 +--
tests/unit/unit1607.c | 2 +-
tests/unit/unit1609.c | 2 +-
5 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/lib/connect.c b/lib/connect.c
index aec397296..79b8094e7 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -628,7 +628,8 @@ void Curl_persistconninfo(struct connectdata *conn)
/* retrieves ip address and port from a sockaddr structure.
note it calls Curl_inet_ntop which sets errno on fail, not SOCKERRNO. */
-bool Curl_addr2string(struct sockaddr *sa, char *addr, long *port)
+bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
+ char *addr, long *port)
{
struct sockaddr_in *si = NULL;
#ifdef ENABLE_IPV6
@@ -636,6 +637,8 @@ bool Curl_addr2string(struct sockaddr *sa, char *addr, long
*port)
#endif
#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
struct sockaddr_un *su = NULL;
+#else
+ (void)salen;
#endif
switch(sa->sa_family) {
@@ -661,8 +664,12 @@ bool Curl_addr2string(struct sockaddr *sa, char *addr,
long *port)
#endif
#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
case AF_UNIX:
- su = (struct sockaddr_un*)sa;
- msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
+ if(salen > sizeof(sa_family_t)) {
+ su = (struct sockaddr_un*)sa;
+ msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
+ }
+ else
+ addr[0] = 0; /* socket with no name */
*port = 0;
return TRUE;
#endif
@@ -690,10 +697,11 @@ void Curl_updateconninfo(struct connectdata *conn,
curl_socket_t sockfd)
char buffer[STRERROR_LEN];
struct Curl_sockaddr_storage ssrem;
struct Curl_sockaddr_storage ssloc;
- curl_socklen_t len;
+ curl_socklen_t plen;
+ curl_socklen_t slen;
#ifdef HAVE_GETPEERNAME
- len = sizeof(struct Curl_sockaddr_storage);
- if(getpeername(sockfd, (struct sockaddr*) &ssrem, &len)) {
+ plen = sizeof(struct Curl_sockaddr_storage);
+ if(getpeername(sockfd, (struct sockaddr*) &ssrem, &plen)) {
int error = SOCKERRNO;
failf(data, "getpeername() failed with errno %d: %s",
error, Curl_strerror(error, buffer, sizeof(buffer)));
@@ -701,9 +709,9 @@ void Curl_updateconninfo(struct connectdata *conn,
curl_socket_t sockfd)
}
#endif
#ifdef HAVE_GETSOCKNAME
- len = sizeof(struct Curl_sockaddr_storage);
+ slen = sizeof(struct Curl_sockaddr_storage);
memset(&ssloc, 0, sizeof(ssloc));
- if(getsockname(sockfd, (struct sockaddr*) &ssloc, &len)) {
+ if(getsockname(sockfd, (struct sockaddr*) &ssloc, &slen)) {
int error = SOCKERRNO;
failf(data, "getsockname() failed with errno %d: %s",
error, Curl_strerror(error, buffer, sizeof(buffer)));
@@ -711,7 +719,7 @@ void Curl_updateconninfo(struct connectdata *conn,
curl_socket_t sockfd)
}
#endif
#ifdef HAVE_GETPEERNAME
- if(!Curl_addr2string((struct sockaddr*)&ssrem,
+ if(!Curl_addr2string((struct sockaddr*)&ssrem, plen,
conn->primary_ip, &conn->primary_port)) {
failf(data, "ssrem inet_ntop() failed with errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
@@ -720,7 +728,7 @@ void Curl_updateconninfo(struct connectdata *conn,
curl_socket_t sockfd)
memcpy(conn->ip_addr_str, conn->primary_ip, MAX_IPADR_LEN);
#endif
#ifdef HAVE_GETSOCKNAME
- if(!Curl_addr2string((struct sockaddr*)&ssloc,
+ if(!Curl_addr2string((struct sockaddr*)&ssloc, slen,
conn->local_ip, &conn->local_port)) {
failf(data, "ssloc inet_ntop() failed with errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
@@ -1049,7 +1057,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
return CURLE_OK;
/* store remote address and port used in this connection attempt */
- if(!Curl_addr2string((struct sockaddr*)&addr.sa_addr,
+ if(!Curl_addr2string((struct sockaddr*)&addr.sa_addr, addr.addrlen,
ipaddress, &port)) {
/* malformed address or bug in inet_ntop, try next address */
failf(data, "sa_addr inet_ntop() failed with errno %d: %s",
diff --git a/lib/connect.h b/lib/connect.h
index e44c4a701..b23085a98 100644
--- a/lib/connect.h
+++ b/lib/connect.h
@@ -51,7 +51,8 @@ timediff_t Curl_timeleft(struct Curl_easy *data,
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
struct connectdata **connp);
-bool Curl_addr2string(struct sockaddr *sa, char *addr, long *port);
+bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
+ char *addr, long *port);
/*
* Check if a connection seems to be alive.
diff --git a/lib/vquic/ngtcp2.c b/lib/vquic/ngtcp2.c
index d98be181c..6b3d53ee0 100644
--- a/lib/vquic/ngtcp2.c
+++ b/lib/vquic/ngtcp2.c
@@ -541,12 +541,11 @@ CURLcode Curl_quic_connect(struct connectdata *conn,
uint8_t paramsbuf[64];
ngtcp2_transport_params params;
ssize_t nwrite;
- (void)addrlen;
qs->conn = conn;
/* extract the used address as a string */
- if(!Curl_addr2string((struct sockaddr*)addr, ipbuf, &port)) {
+ if(!Curl_addr2string((struct sockaddr*)addr, addrlen, ipbuf, &port)) {
char buffer[STRERROR_LEN];
failf(data, "ssrem inet_ntop() failed with errno %d: %s",
errno, Curl_strerror(errno, buffer, sizeof(buffer)));
diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c
index 458604229..a8b0331ce 100644
--- a/tests/unit/unit1607.c
+++ b/tests/unit/unit1607.c
@@ -150,7 +150,7 @@ UNITTEST_START
if(tests[i].address[j] == &skip)
continue;
- if(addr && !Curl_addr2string(addr->ai_addr,
+ if(addr && !Curl_addr2string(addr->ai_addr, addr->ai_addrlen,
ipaddress, &port)) {
fprintf(stderr, "%s:%d tests[%d] failed. getaddressinfo failed.\n",
__FILE__, __LINE__, i);
diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c
index d919c9ea9..8223a147c 100644
--- a/tests/unit/unit1609.c
+++ b/tests/unit/unit1609.c
@@ -150,7 +150,7 @@ UNITTEST_START
if(!addr && !tests[i].address[j])
break;
- if(addr && !Curl_addr2string(addr->ai_addr,
+ if(addr && !Curl_addr2string(addr->ai_addr, addr->ai_addrlen,
ipaddress, &port)) {
fprintf(stderr, "%s:%d tests[%d] failed. Curl_addr2string failed.\n",
__FILE__, __LINE__, i);
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [gnurl] 181/220: ngtcp2: build latest ngtcp2 and ngtcp2_crypto_openssl, (continued)
- [GNUnet-SVN] [gnurl] 181/220: ngtcp2: build latest ngtcp2 and ngtcp2_crypto_openssl, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 175/220: ngtcp2: Build with latest ngtcp2 and ngtcp2_crypto_openssl, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 187/220: quiche: expire when poll returned data, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 168/220: travis: disable ngtcp2 builds (temporarily), gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 153/220: curl: make --libcurl use CURL_HTTP_VERSION_3, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 159/220: travis: add a build using ngtcp2 + nghttp3 (and a patched OpenSSL), gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 158/220: travis: bump to using nghttp2 version 1.39.2, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 178/220: CURLINFO docs: mention that in redirects times are added, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 190/220: CMake: remove needless newlines at end of gss variables, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 188/220: CMake: use platform dependent name for dlopen() library, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 191/220: Curl_addr2string: take an addrlen argument too,
gnunet <=
- [GNUnet-SVN] [gnurl] 192/220: THANKS: remove duplicate, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 157/220: docs/examples/curlx: fix errors, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 161/220: ngtcp2: accept upload via callback, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 169/220: quiche: send the HTTP body correctly on callback uploads, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 186/220: quiche: decrease available buffer size, don't assign it!, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 180/220: ngtcp2: set flow control window to stream buffer size, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 183/220: plan9: fix installation instructions, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 184/220: curl: fix include conditions, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 211/220: urlapi: one colon is enough for the strspn() input (typo), gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 197/220: urldata: avoid 'generic', use dedicated pointers, gnunet, 2019/09/12