Fix a coredump in the logging functions if gethostname(2) fails
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
This commit is contained in:
41
sudo.c
41
sudo.c
@@ -449,6 +449,7 @@ init_vars(sudo_mode)
|
|||||||
int sudo_mode;
|
int sudo_mode;
|
||||||
{
|
{
|
||||||
char *p, thost[MAXHOSTNAMELEN];
|
char *p, thost[MAXHOSTNAMELEN];
|
||||||
|
int nohostname;
|
||||||
|
|
||||||
/* Sanity check command from user. */
|
/* Sanity check command from user. */
|
||||||
if (user_cmnd == NULL && strlen(NewArgv[0]) >= MAXPATHLEN) {
|
if (user_cmnd == NULL && strlen(NewArgv[0]) >= MAXPATHLEN) {
|
||||||
@@ -472,20 +473,22 @@ init_vars(sudo_mode)
|
|||||||
* "host" is the (possibly fully-qualified) hostname and
|
* "host" is the (possibly fully-qualified) hostname and
|
||||||
* "shost" is the unqualified form of the hostname.
|
* "shost" is the unqualified form of the hostname.
|
||||||
*/
|
*/
|
||||||
if ((gethostname(thost, sizeof(thost)))) {
|
/* nohostname = gethostname(thost, sizeof(thost)); */
|
||||||
user_host = "localhost";
|
nohostname = -1;
|
||||||
log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");
|
if (nohostname)
|
||||||
} else
|
user_host = user_shost = "localhost";
|
||||||
user_host = estrdup(thost);
|
|
||||||
if (def_flag(I_FQDN))
|
|
||||||
set_fqdn();
|
|
||||||
else {
|
else {
|
||||||
if ((p = strchr(user_host, '.'))) {
|
user_host = estrdup(thost);
|
||||||
*p = '\0';
|
if (def_flag(I_FQDN))
|
||||||
user_shost = estrdup(user_host);
|
set_fqdn();
|
||||||
*p = '.';
|
else {
|
||||||
} else {
|
if ((p = strchr(user_host, '.'))) {
|
||||||
user_shost = 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() */
|
/* 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.
|
* 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);
|
log_error(errflags, "unknown login class: %s", login_class);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int
|
static void
|
||||||
set_loginclass(pw)
|
set_loginclass(pw)
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
{
|
{
|
||||||
@@ -1203,10 +1209,9 @@ static void
|
|||||||
usage(exit_val)
|
usage(exit_val)
|
||||||
int exit_val;
|
int exit_val;
|
||||||
{
|
{
|
||||||
(void) fprintf(stderr,
|
|
||||||
"usage: %s -V | -h | -L | -l | -v | -k | -K | [-H] [-S] [-b]\n%*s",
|
(void) fprintf(stderr, "usage: sudo -V | -h | -L | -l | -v | -k | -K | %s",
|
||||||
Argv[0], (int) strlen(Argv[0]) + 8, " ");
|
"[-H] [-S] [-b] [-p prompt]\n [-u username/#uid] ");
|
||||||
(void) fprintf(stderr, "[-p prompt] [-u username/#uid] ");
|
|
||||||
#ifdef HAVE_LOGIN_CAP_H
|
#ifdef HAVE_LOGIN_CAP_H
|
||||||
(void) fprintf(stderr, "[-c class] ");
|
(void) fprintf(stderr, "[-c class] ");
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user