summaryrefslogtreecommitdiff
path: root/openbsd-compat/fake-getaddrinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/fake-getaddrinfo.c')
-rw-r--r--openbsd-compat/fake-getaddrinfo.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-getaddrinfo.c
index ebf736670..1ca7ab051 100644
--- a/openbsd-compat/fake-getaddrinfo.c
+++ b/openbsd-compat/fake-getaddrinfo.c
@@ -10,10 +10,8 @@
10 */ 10 */
11 11
12#include "includes.h" 12#include "includes.h"
13#include "xmalloc.h"
14#include "ssh.h"
15 13
16RCSID("$Id: fake-getaddrinfo.c,v 1.9 2003/06/04 23:48:33 djm Exp $"); 14RCSID("$Id: fake-getaddrinfo.c,v 1.10 2003/06/05 00:04:12 djm Exp $");
17 15
18#ifndef HAVE_GAI_STRERROR 16#ifndef HAVE_GAI_STRERROR
19char * 17char *
@@ -52,7 +50,9 @@ addrinfo *malloc_ai(int port, u_long addr, const struct addrinfo *hints)
52{ 50{
53 struct addrinfo *ai; 51 struct addrinfo *ai;
54 52
55 ai = xmalloc(sizeof(*ai) + sizeof(struct sockaddr_in)); 53 ai = malloc(sizeof(*ai) + sizeof(struct sockaddr_in));
54 if (ai == NULL)
55 return (NULL);
56 56
57 memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in)); 57 memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in));
58 58
@@ -105,16 +105,22 @@ getaddrinfo(const char *hostname, const char *servname,
105 if (hostname && inet_aton(hostname, &in) != 0) 105 if (hostname && inet_aton(hostname, &in) != 0)
106 addr = in.s_addr; 106 addr = in.s_addr;
107 *res = malloc_ai(port, addr, hints); 107 *res = malloc_ai(port, addr, hints);
108 if (*res == NULL)
109 return (EAI_MEMORY);
108 return (0); 110 return (0);
109 } 111 }
110 112
111 if (!hostname) { 113 if (!hostname) {
112 *res = malloc_ai(port, htonl(0x7f000001), hints); 114 *res = malloc_ai(port, htonl(0x7f000001), hints);
115 if (*res == NULL)
116 return (EAI_MEMORY);
113 return (0); 117 return (0);
114 } 118 }
115 119
116 if (inet_aton(hostname, &in)) { 120 if (inet_aton(hostname, &in)) {
117 *res = malloc_ai(port, in.s_addr, hints); 121 *res = malloc_ai(port, in.s_addr, hints);
122 if (*res == NULL)
123 return (EAI_MEMORY);
118 return (0); 124 return (0);
119 } 125 }
120 126
@@ -126,11 +132,16 @@ getaddrinfo(const char *hostname, const char *servname,
126 if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { 132 if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
127 struct addrinfo *cur, *prev; 133 struct addrinfo *cur, *prev;
128 134
129 cur = prev = NULL; 135 cur = prev = *res = NULL;
130 for (i = 0; hp->h_addr_list[i]; i++) { 136 for (i = 0; hp->h_addr_list[i]; i++) {
131 struct in_addr *in = (struct in_addr *)hp->h_addr_list[i]; 137 struct in_addr *in = (struct in_addr *)hp->h_addr_list[i];
132 138
133 cur = malloc_ai(port, in->s_addr, hints); 139 cur = malloc_ai(port, in->s_addr, hints);
140 if (cur == NULL) {
141 if (*res != NULL)
142 freeaddrinfo(*res);
143 return (EAI_MEMORY);
144 }
134 if (prev) 145 if (prev)
135 prev->ai_next = cur; 146 prev->ai_next = cur;
136 else 147 else