]> granicus.if.org Git - sudo/commitdiff
Fix a coredump in the logging functions if gethostname(2) fails
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 27 Oct 2000 22:41:48 +0000 (22:41 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 27 Oct 2000 22:41:48 +0000 (22:41 +0000)
by deferring the call to log_error() until things are better setup.

Fix return value of set_loginclass() in non-BSD-auth case.

Hard-code 'sudo' in the usage message so we can fit more options on a line

sudo.c

diff --git a/sudo.c b/sudo.c
index e6df97abe0454d39199c125a7f60fe5ff3d13cba..79fe1ede57e0b4935b66742f76449b7ea8242b4c 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -449,6 +449,7 @@ init_vars(sudo_mode)
     int sudo_mode;
 {
     char *p, thost[MAXHOSTNAMELEN];
+    int nohostname;
 
     /* Sanity check command from user. */
     if (user_cmnd == NULL && strlen(NewArgv[0]) >= MAXPATHLEN) {
@@ -472,20 +473,22 @@ init_vars(sudo_mode)
      * "host" is the (possibly fully-qualified) hostname and
      * "shost" is the unqualified form of the hostname.
      */
-    if ((gethostname(thost, sizeof(thost)))) {
-       user_host = "localhost";
-       log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");
-    } else
-       user_host = estrdup(thost);
-    if (def_flag(I_FQDN))
-       set_fqdn();
+    /* nohostname = gethostname(thost, sizeof(thost)); */
+    nohostname = -1;
+    if (nohostname)
+       user_host = user_shost = "localhost";
     else {
-       if ((p = strchr(user_host, '.'))) {
-           *p = '\0';
-           user_shost = estrdup(user_host);
-           *p = '.';
-       } else {
-           user_shost = user_host;
+       user_host = estrdup(thost);
+       if (def_flag(I_FQDN))
+           set_fqdn();
+       else {
+           if ((p = strchr(user_host, '.'))) {
+               *p = '\0';
+               user_shost = estrdup(user_host);
+               *p = '.';
+           } else {
+               user_shost = user_host;
+           }
        }
     }
 
@@ -517,6 +520,9 @@ init_vars(sudo_mode)
 
     /* It is now safe to use log_error() and set_perms() */
 
+    if (nohostname)
+       log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");
+
     /*
      * Get current working directory.  Try as user, fall back to root.
      */
@@ -1116,7 +1122,7 @@ set_loginclass(pw)
        log_error(errflags, "unknown login class: %s", login_class);
 }
 #else
-static int
+static void
 set_loginclass(pw)
     struct passwd *pw;
 {
@@ -1203,10 +1209,9 @@ static void
 usage(exit_val)
     int exit_val;
 {
-    (void) fprintf(stderr,
-       "usage: %s -V | -h | -L | -l | -v | -k | -K | [-H] [-S] [-b]\n%*s",
-       Argv[0], (int) strlen(Argv[0]) + 8, " ");
-    (void) fprintf(stderr, "[-p prompt] [-u username/#uid] ");
+
+    (void) fprintf(stderr, "usage: sudo -V | -h | -L | -l | -v | -k | -K | %s",
+       "[-H] [-S] [-b] [-p prompt]\n            [-u username/#uid] ");
 #ifdef HAVE_LOGIN_CAP_H
     (void) fprintf(stderr, "[-c class] ");
 #endif