commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_2-10-g9c2329


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_2-10-g9c23298
Date: Thu, 13 Mar 2014 21:31:08 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  9c23298d9feff6333c8ec515bd607b023a360ff6 (commit)
      from  5f8a021b32df3d31cd98f6c85ad7c8f2b8308506 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=9c23298d9feff6333c8ec515bd607b023a360ff6


commit 9c23298d9feff6333c8ec515bd607b023a360ff6
Author: Mats Erik Andersson <address@hidden>
Date:   Tue Mar 11 13:12:06 2014 +0100

    hostname: Sanity checks in corner cases.
    
    Improve response when a resolver is missing.

diff --git a/ChangeLog b/ChangeLog
index c6045f1..afebf42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2014-03-10  Mats Erik Andersson  <address@hidden>
+
+       hostname: Sanity checks in corner cases.
+
+       * src/hostname.c (get_name): Use reply from get_fqdn()
+       only if it gave a host name, not the artificial "(none)".
+       (set_name): Reject an empty host name.
+       (parse_file): Initialize NAME.  Improve error message
+       when getline() claims empty input.  Break out of loop
+       only if sscanf() produced a printable string.
+
 2014-02-22  Mats Erik Andersson  <address@hidden>
 
        ifconfig: Allow flags richer than 16 bits.
diff --git a/src/hostname.c b/src/hostname.c
index 2a99154..95a2698 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -175,6 +175,7 @@ get_name (const hostname_arguments *const args)
 
   if (!sname)
     error (EXIT_FAILURE, errno, "cannot determine name");
+
   if (args->hostname_alias == 1)
     name = get_aliases (sname);
   else if (args->hostname_fqdn == 1)
@@ -182,11 +183,20 @@ get_name (const hostname_arguments *const args)
       name = get_fqdn (sname);
 
       if (args->hostname_dns_domain == 1 || args->hostname_short == 1)
-        {
-          free (sname);
-          sname = name;
-          name = NULL;
-        }
+       {
+         /* Eliminate empty replies, as well as `(none)'.  */
+         if (name && *name && *name != '(')
+           {
+             free (sname);
+             sname = name;
+             name = NULL;
+           }
+         else if (name && *name == '(')
+           {
+             free (name);
+             name = NULL;
+           }
+       }
 
       if (args->hostname_dns_domain == 1)
         name = get_dns_domain_name (sname);
@@ -222,6 +232,9 @@ set_name (const hostname_arguments *const args)
     hostname_new = args->hostname_new;
 
   size = strlen (hostname_new);
+  if (!size)
+    error (EXIT_FAILURE, 0, "Empty hostname");
+
   status = (*set_name_action) (hostname_new, size);
   if (status == -1)
     error (EXIT_FAILURE, errno, "sethostname");
@@ -370,7 +383,7 @@ static char *
 parse_file (const char *const file_name)
 {
   char *buffer = NULL;
-  char *name;
+  char *name = NULL;
   FILE *file;
   ssize_t nread;
   size_t size = 0;
@@ -379,17 +392,19 @@ parse_file (const char *const file_name)
   if (file == NULL)
     error (EXIT_FAILURE, errno, "fopen");
 
+  errno = 0;                   /* Portability issue!  */
+
   do
     {
       nread = getline (&buffer, &size, file);
       if (nread == -1)
-       error (EXIT_FAILURE, errno, "getline");
+       error (EXIT_FAILURE, errno, "getline%s", errno ? "" : ": No text");
 
       if (buffer[0] != '#')
         {
-          name = xmalloc (sizeof (char) * nread);
-          sscanf (buffer, "%s", name);
-          break;
+         name = (char *) xmalloc (sizeof (char) * nread);
+         if (sscanf (buffer, "%s", name)  == 1)
+           break;
         }
     }
   while (feof (file) == 0);

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog      |   11 +++++++++++
 src/hostname.c |   35 +++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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