summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2003-06-05 10:04:12 +1000
committerDamien Miller <djm@mindrot.org>2003-06-05 10:04:12 +1000
commitb95bb7f9b13905ade12cac848e34339ae8a1cc2f (patch)
tree6bba63edd710e839b5e6523b391346b0a81025bd /openbsd-compat
parentceb3136f5f121e0d6d3a78dcc52c6bf186a7f872 (diff)
- (djm) Don't use xmalloc() or pull in toplevel headers in fake-* code
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/fake-getaddrinfo.c21
-rw-r--r--openbsd-compat/fake-getaddrinfo.h10
2 files changed, 21 insertions, 10 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
diff --git a/openbsd-compat/fake-getaddrinfo.h b/openbsd-compat/fake-getaddrinfo.h
index eaba323d1..62e93ddbc 100644
--- a/openbsd-compat/fake-getaddrinfo.h
+++ b/openbsd-compat/fake-getaddrinfo.h
@@ -1,4 +1,4 @@
1/* $Id: fake-getaddrinfo.h,v 1.5 2003/06/04 23:48:33 djm Exp $ */ 1/* $Id: fake-getaddrinfo.h,v 1.6 2003/06/05 00:04:12 djm Exp $ */
2 2
3#ifndef _FAKE_GETADDRINFO_H 3#ifndef _FAKE_GETADDRINFO_H
4#define _FAKE_GETADDRINFO_H 4#define _FAKE_GETADDRINFO_H
@@ -27,16 +27,16 @@ struct addrinfo {
27#endif /* !HAVE_STRUCT_ADDRINFO */ 27#endif /* !HAVE_STRUCT_ADDRINFO */
28 28
29#ifndef HAVE_GETADDRINFO 29#ifndef HAVE_GETADDRINFO
30int getaddrinfo(const char *hostname, const char *servname, 30int getaddrinfo(const char *, const char *,
31 const struct addrinfo *hints, struct addrinfo **res); 31 const struct addrinfo *, struct addrinfo **);
32#endif /* !HAVE_GETADDRINFO */ 32#endif /* !HAVE_GETADDRINFO */
33 33
34#ifndef HAVE_GAI_STRERROR 34#ifndef HAVE_GAI_STRERROR
35char *gai_strerror(int ecode); 35char *gai_strerror(int);
36#endif /* !HAVE_GAI_STRERROR */ 36#endif /* !HAVE_GAI_STRERROR */
37 37
38#ifndef HAVE_FREEADDRINFO 38#ifndef HAVE_FREEADDRINFO
39void freeaddrinfo(struct addrinfo *ai); 39void freeaddrinfo(struct addrinfo *);
40#endif /* !HAVE_FREEADDRINFO */ 40#endif /* !HAVE_FREEADDRINFO */
41 41
42#endif /* _FAKE_GETADDRINFO_H */ 42#endif /* _FAKE_GETADDRINFO_H */