summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Alm <robert2.alm@sonymobile.com>2014-11-25 13:28:11 +0100
committerElliott Hughes <enh@google.com>2014-11-27 11:01:50 -0800
commit3638a83657d9833816e579778394a40ae4178868 (patch)
treeadb015f81103dc8eefe956c7e085c58d89fa1861
parent461403270593363dfe0b75db9f5e9f454b4258d2 (diff)
downloadbionic-3638a83657d9833816e579778394a40ae4178868.zip
bionic-3638a83657d9833816e579778394a40ae4178868.tar.gz
bionic-3638a83657d9833816e579778394a40ae4178868.tar.bz2
Add error-check when mapping socket to fd
The call to fdopen can fail in several ways. The fprintf on the next line will then dereference a NULL-pointer FILE*. Added a NULL-check, closed the socket, returned system error and added a comment about it. Change-Id: I7a6b26aa3c79452b1fdd76af12dfa75da88cbad7
-rw-r--r--libc/dns/net/getaddrinfo.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 132a090..1ebd222 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -463,6 +463,15 @@ android_getaddrinfo_proxy(
// Send the request.
proxy = fdopen(sock, "r+");
+ if (proxy == NULL) {
+ // Failed to map sock to FILE*. Check errno for the cause.
+ // @sonymobile.com saw failures in automated testing, but
+ // couldn't reproduce it for debugging.
+ // Fail with EAI_SYSTEM and let callers handle the failure.
+ close(sock);
+ return EAI_SYSTEM;
+ }
+
if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d %u",
hostname == NULL ? "^" : hostname,
servname == NULL ? "^" : servname,