]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
* support/export/hostname.c (get_reliable_hostbyaddr): Fix crash
authorchip <chip>
Tue, 9 Sep 2003 16:01:57 +0000 (16:01 +0000)
committerchip <chip>
Tue, 9 Sep 2003 16:01:57 +0000 (16:01 +0000)
on invalid reverse DNS.

ChangeLog
support/export/hostname.c

index 26fc697c1016605f49943a4a89776115c820145e..279c1f80aecf794910333efe63536add5c33936e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-09-09  Chip Salzenberg  <chip@pobox.com>
+
+       * support/export/hostname.c (get_reliable_hostbyaddr): Fix crash
+       on invalid reverse DNS.
+
 2003-08-22  Chip Salzenberg  <chip@pobox.com>
 
        * utils/statd/{log.h,log.c}: Rename log() to note() and L_* to
index f88e0a485290cb878ab670f4b6917648c3903485..3957d80069c5510b9faa6e60a4c876d00573ace5 100644 (file)
@@ -224,46 +224,45 @@ matchhostname (const char *h1, const char *h2)
 struct hostent *
 get_reliable_hostbyaddr(const char *addr, int len, int type)
 {
-       struct hostent *hp;
+       struct hostent *hp = NULL;
 
+       struct hostent *reverse;
+       struct hostent *forward;
        char **sp;
-       struct hostent *forward = NULL;
-       char *tmpname;
 
-       hp = gethostbyaddr(addr, len , type);
-       if (!hp)
-               return hp;
+       reverse = gethostbyaddr (addr, len, type);
+       if (!reverse)
+               return NULL;
 
        /* must make sure the hostent is authorative. */
 
-       hp = hostent_dup (hp);
-       tmpname = xstrdup((hp)->h_name);
-       if (tmpname) {
-               forward = gethostbyname(tmpname);
-               free(tmpname);
-       }
+       reverse = hostent_dup (reverse);
+       forward = gethostbyname (reverse->h_name);
+
        if (forward) {
                /* now make sure the "addr" is in the list */
                for (sp = forward->h_addr_list ; *sp ; sp++) {
-                       if (memcmp(*sp, addr, forward->h_length)==0)
+                       if (memcmp (*sp, addr, forward->h_length) == 0)
                                break;
                }
-               
-               if (!*sp) {
+
+               if (*sp) {
+                       /* it's valid */
+                       hp = hostent_dup (forward);
+               }
+               else {
                        /* it was a FAKE */
-                       xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse",
-                            forward->h_name, inet_ntoa(*(struct in_addr*)addr));
-                       return NULL;
+                       xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't match reverse",
+                             reverse->h_name, inet_ntoa(*(struct in_addr*)addr));
                }
-               free (hp);
-               hp = hostent_dup (forward);
        }
        else {
                /* never heard of it. misconfigured DNS? */
-               xlog(L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist",
-                    forward->h_name, inet_ntoa(*(struct in_addr*)addr));
-               return NULL;
+               xlog (L_WARNING, "Fake hostname %s for %s - forward lookup doesn't exist",
+                     reverse->h_name, inet_ntoa(*(struct in_addr*)addr));
        }
+
+       free (reverse);
        return hp;
 }