* amd/amq_svc.c (amqsvc_is_client_allowed): rewrite function to
authorErez Zadok <ezk@cs.sunysb.edu>
Sat, 28 May 2005 16:39:23 +0000 (16:39 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Sat, 28 May 2005 16:39:23 +0000 (16:39 +0000)
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.

ChangeLog
amd/amq_svc.c

index e6ffea9c234605d76f118cb207d24da4aa6eaf75..39292c75babd30c42804c74948f5554cb134351a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-05-28  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * 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  <ezk@cs.sunysb.edu>
index 7ff3bab1f357dc1ee42fdded087b1a55dd0ea908..382f2e1878934d4915a18ba470cabc7cd9da15d8 100644 (file)
@@ -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) */