From ea5942b4cfb56eeb7375e3af2ec76545f551b4df Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 31 Dec 2015 11:12:57 +0100 Subject: [PATCH 1/2] Bail out early when no memory is available. --- src/posix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/posix.c b/src/posix.c index 8d86aa8bf..de9181a42 100644 --- a/src/posix.c +++ b/src/posix.c @@ -62,7 +62,10 @@ int p_getaddrinfo( ai = ainfo; for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) { - ai->ai_next = malloc(sizeof(struct addrinfo)); + if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) { + p_freeaddrinfo(ainfo); + return -1; + } memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo)); memcpy(&ai->ai_next->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[p], From 9f9df4b6e05cc5950953177a1cb48739f1ddfc29 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 31 Dec 2015 11:13:21 +0100 Subject: [PATCH 2/2] Copy into the correct destination. --- src/posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posix.c b/src/posix.c index de9181a42..c7201ba14 100644 --- a/src/posix.c +++ b/src/posix.c @@ -66,7 +66,7 @@ int p_getaddrinfo( p_freeaddrinfo(ainfo); return -1; } - memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo)); + memcpy(ai->ai_next, ainfo, sizeof(struct addrinfo)); memcpy(&ai->ai_next->ai_addr_in.sin_addr, ainfo->ai_hostent->h_addr_list[p], ainfo->ai_hostent->h_length);