From: Erez Zadok Date: Sat, 28 May 2005 16:39:23 +0000 (+0000) Subject: * amd/amq_svc.c (amqsvc_is_client_allowed): rewrite function to X-Git-Tag: am-utils-6_1_rc7~8 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=aaeb547ed468f9b7e902575e8a275efed4defd98;p=am-utils-6.0.git * amd/amq_svc.c (amqsvc_is_client_allowed): rewrite function to avoid only use of alloca() in am-utils, and to use strdup explicitly. This way we can avoid using alloca, a feature that's not portable on various systems. --- diff --git a/ChangeLog b/ChangeLog index e6ffea9..39292c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-05-28 Erez Zadok + * amd/amq_svc.c (amqsvc_is_client_allowed): rewrite function to + avoid only use of alloca() in am-utils, and to use strdup + explicitly. This way we can avoid using alloca, a feature that's + not portable on various systems. + * amq/amq.c: remove unused lint/rcsid cruft. 2005-05-27 Erez Zadok diff --git a/amd/amq_svc.c b/amd/amq_svc.c index 7ff3bab..382f2e1 100644 --- a/amd/amq_svc.c +++ b/amd/amq_svc.c @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * - * $Id: amq_svc.c,v 1.16 2005/01/03 20:56:45 ezk Exp $ + * $Id: amq_svc.c,v 1.17 2005/05/28 16:39:23 ezk Exp $ * */ @@ -68,34 +68,44 @@ static int amqsvc_is_client_allowed(const struct sockaddr_in *addr, char *remote) { struct hostent *h; - char *name, **ad; + char *name = NULL, **ad; + int ret = 0; /* default is 0==denied */ /* Check IP address */ - if (hosts_ctl(AMD_SERVICE_NAME, "", remote, "")) - return 1; + if (hosts_ctl(AMD_SERVICE_NAME, "", remote, "")) { + ret = 1; + goto out; + } /* Get address */ if (!(h = gethostbyaddr((const char *)&(addr->sin_addr), sizeof(addr->sin_addr), AF_INET))) - return 0; - if (!(name = alloca(strlen(h->h_name)+1))) - return 0; - strcpy(name, h->h_name); + goto out; + if (!(name = strdup(h->h_name))) + goto out; /* Paranoia check */ if (!(h = gethostbyname(name))) - return 0; + goto out; for (ad = h->h_addr_list; *ad; ad++) if (!memcmp(*ad, &(addr->sin_addr), h->h_length)) break; if (!*ad) - return 0; - if (hosts_ctl(AMD_SERVICE_NAME, "", h->h_name, "")) + goto out; + if (hosts_ctl(AMD_SERVICE_NAME, "", h->h_name, "")) { return 1; + goto out; + } /* Check aliases */ for (ad = h->h_aliases; *ad; ad++) - if (hosts_ctl(AMD_SERVICE_NAME, "", *ad, "")) + if (hosts_ctl(AMD_SERVICE_NAME, "", *ad, "")) { return 1; - return 0; + goto out; + } + + out: + if (name) + XFREE(name); + return ret; } #endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */