From b95bb7f9b13905ade12cac848e34339ae8a1cc2f Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Thu, 5 Jun 2003 10:04:12 +1000 Subject: [PATCH] - (djm) Don't use xmalloc() or pull in toplevel headers in fake-* code --- ChangeLog | 3 ++- openbsd-compat/fake-getaddrinfo.c | 21 ++++++++++++++++----- openbsd-compat/fake-getaddrinfo.h | 10 +++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f7612004..3cfbd1602 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ - (djm) Implement paranoid priv dropping checks, based on: "SetUID demystified" - Hao Chen, David Wagner and Drew Dean Proceedings of USENIX Security Symposium 2002 + - (djm) Don't use xmalloc() or pull in toplevel headers in fake-* code 20030604 - (djm) Bug #573 - Remove unneeded Krb headers and compat goop. Patch from @@ -465,4 +466,4 @@ - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. Report from murple@murple.net, diagnosis from dtucker@zip.com.au -$Id: ChangeLog,v 1.2783 2003/06/04 23:53:42 djm Exp $ +$Id: ChangeLog,v 1.2784 2003/06/05 00:04:12 djm Exp $ 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 @@ */ #include "includes.h" -#include "xmalloc.h" -#include "ssh.h" -RCSID("$Id: fake-getaddrinfo.c,v 1.9 2003/06/04 23:48:33 djm Exp $"); +RCSID("$Id: fake-getaddrinfo.c,v 1.10 2003/06/05 00:04:12 djm Exp $"); #ifndef HAVE_GAI_STRERROR char * @@ -52,7 +50,9 @@ addrinfo *malloc_ai(int port, u_long addr, const struct addrinfo *hints) { struct addrinfo *ai; - ai = xmalloc(sizeof(*ai) + sizeof(struct sockaddr_in)); + ai = malloc(sizeof(*ai) + sizeof(struct sockaddr_in)); + if (ai == NULL) + return (NULL); memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in)); @@ -105,16 +105,22 @@ getaddrinfo(const char *hostname, const char *servname, if (hostname && inet_aton(hostname, &in) != 0) addr = in.s_addr; *res = malloc_ai(port, addr, hints); + if (*res == NULL) + return (EAI_MEMORY); return (0); } if (!hostname) { *res = malloc_ai(port, htonl(0x7f000001), hints); + if (*res == NULL) + return (EAI_MEMORY); return (0); } if (inet_aton(hostname, &in)) { *res = malloc_ai(port, in.s_addr, hints); + if (*res == NULL) + return (EAI_MEMORY); return (0); } @@ -126,11 +132,16 @@ getaddrinfo(const char *hostname, const char *servname, if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { struct addrinfo *cur, *prev; - cur = prev = NULL; + cur = prev = *res = NULL; for (i = 0; hp->h_addr_list[i]; i++) { struct in_addr *in = (struct in_addr *)hp->h_addr_list[i]; cur = malloc_ai(port, in->s_addr, hints); + if (cur == NULL) { + if (*res != NULL) + freeaddrinfo(*res); + return (EAI_MEMORY); + } if (prev) prev->ai_next = cur; 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 @@ -/* $Id: fake-getaddrinfo.h,v 1.5 2003/06/04 23:48:33 djm Exp $ */ +/* $Id: fake-getaddrinfo.h,v 1.6 2003/06/05 00:04:12 djm Exp $ */ #ifndef _FAKE_GETADDRINFO_H #define _FAKE_GETADDRINFO_H @@ -27,16 +27,16 @@ struct addrinfo { #endif /* !HAVE_STRUCT_ADDRINFO */ #ifndef HAVE_GETADDRINFO -int getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res); +int getaddrinfo(const char *, const char *, + const struct addrinfo *, struct addrinfo **); #endif /* !HAVE_GETADDRINFO */ #ifndef HAVE_GAI_STRERROR -char *gai_strerror(int ecode); +char *gai_strerror(int); #endif /* !HAVE_GAI_STRERROR */ #ifndef HAVE_FREEADDRINFO -void freeaddrinfo(struct addrinfo *ai); +void freeaddrinfo(struct addrinfo *); #endif /* !HAVE_FREEADDRINFO */ #endif /* _FAKE_GETADDRINFO_H */