Skip to content

Commit 2d0e319

Browse files
committed
Fix "sudo -l command args", broken in sudo 1.9.13.
The value of user_args should not contain the command to be run in "sudo -l command args", only the arguments of the command being checked. This restores the pre-1.9.13 behavior. GitHub issue #249 --HG-- branch : 1.9
1 parent 6fe3afb commit 2d0e319

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

plugins/sudoers/logging.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ log_denial(int status, bool inform_user)
322322
"sudo on %s.\n"), user_name, user_srunhost);
323323
} else {
324324
sudo_printf(SUDO_CONV_ERROR_MSG, _("Sorry, user %s is not allowed "
325-
"to execute '%s%s%s' as %s%s%s on %s.\n"),
326-
user_name, user_cmnd, user_args ? " " : "",
327-
user_args ? user_args : "",
325+
"to execute '%s%s%s%s' as %s%s%s on %s.\n"),
326+
user_name, user_cmnd, list_cmnd ? list_cmnd : "",
327+
user_args ? " " : "", user_args ? user_args : "",
328328
list_pw ? list_pw->pw_name : runas_pw ?
329329
runas_pw->pw_name : user_name, runas_gr ? ":" : "",
330330
runas_gr ? runas_gr->gr_name : "", user_host);

plugins/sudoers/parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,8 @@ display_cmnd(struct sudo_nss_list *snl, struct passwd *pw)
10671067
break;
10681068
}
10691069
if (match == ALLOW) {
1070-
/* For "sudo -l cmd" user_args includes the command being checked. */
1071-
const int len = sudo_printf(SUDO_CONV_INFO_MSG, "%s\n", user_args);
1070+
const int len = sudo_printf(SUDO_CONV_INFO_MSG, "%s%s%s\n",
1071+
list_cmnd, user_args ? " " : "", user_args ? user_args : "");
10721072
ret = len < 0 ? -1 : true;
10731073
}
10741074
debug_return_int(ret);

plugins/sudoers/sudoers.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,14 @@ set_cmnd(void)
10791079
/* set user_args */
10801080
free(user_args);
10811081
user_args = NULL;
1082-
if (NewArgc > 1) {
1082+
if (ISSET(sudo_mode, MODE_CHECK)) {
1083+
if (NewArgc > 2) {
1084+
/* Skip the command being listed in NewArgv[1]. */
1085+
user_args = strvec_join(NewArgv + 2, ' ', NULL);
1086+
if (user_args == NULL)
1087+
debug_return_int(NOT_FOUND_ERROR);
1088+
}
1089+
} else if (NewArgc > 1) {
10831090
if (ISSET(sudo_mode, MODE_SHELL|MODE_LOGIN_SHELL) &&
10841091
ISSET(sudo_mode, MODE_RUN)) {
10851092
/*

0 commit comments

Comments
 (0)