bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [patch] Fix possible segfault in localhost


From: Guillem Jover
Subject: [bug-inetutils] [patch] Fix possible segfault in localhost
Date: Sat, 21 Oct 2006 16:35:59 +0300
User-agent: Mutt/1.5.13 (2006-08-11)

Hi,

More stuff from Coverity. In this case if gethostbyname gets passed a
NULL due to gethostname failing and bug being 0, the former would
segfault. The change is essentially a missing "else", the other
changes are indentation fixups.


2006-10-21  Guillem Jover  <address@hidden>

        * libinetutils/localhost.c (localhost): Determine the FQDN only
        if gethostname did not fail.


Index: libinetutils/localhost.c
===================================================================
RCS file: /sources/inetutils/inetutils/libinetutils/localhost.c,v
retrieving revision 1.13
diff -u -r1.13 localhost.c
--- libinetutils/localhost.c    2 Dec 2005 14:05:28 -0000       1.13
+++ libinetutils/localhost.c    21 Oct 2006 13:32:06 -0000
@@ -77,22 +77,23 @@
       free (buf);
       buf = 0;
     }
+  else
+    /* Determine FQDN */
+    {
+      struct hostent *hp = gethostbyname(buf);
 
-  /* Determine FQDN */
-  {
-    struct hostent *hp = gethostbyname(buf);
+      if (hp)
+        {
+         struct in_addr addr;
+         addr.s_addr = *(unsigned int*) hp->h_addr;
+         hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
+         if (hp)
+           {
+             free(buf);
+             buf = strdup(hp->h_name);
+           }
+        }
+    }
 
-    if (hp)
-      {
-       struct in_addr addr;
-       addr.s_addr = *(unsigned int*) hp->h_addr;
-       hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
-       if (hp)
-         {
-           free(buf);
-           buf = strdup(hp->h_name);
-         }
-      }
-  }
   return buf;
 }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]