Skip to content

Instantly share code, notes, and snippets.

@saidelike
Created July 6, 2021 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saidelike/8d0c921d8c233f8237113d3ee9937d7e to your computer and use it in GitHub Desktop.
Save saidelike/8d0c921d8c233f8237113d3ee9937d7e to your computer and use it in GitHub Desktop.
//sudo_1.8.23-9.el7/plugins/sudoers/sudoers.c
static int
set_cmnd(void)
{
...
if (sudo_mode & (MODE_RUN | MODE_EDIT | MODE_CHECK)) {
...
/* set user_args */
if (NewArgc > 1) {
char *to, *from, **av;
size_t size, n;
/* Alloc and build up user_args. */
for (size = 0, av = NewArgv + 1; *av; av++)
size += strlen(*av) + 1;
[6] if (size == 0 || (user_args = malloc(size)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}
if (ISSET(sudo_mode, MODE_SHELL|MODE_LOGIN_SHELL)) {
/*
* When running a command via a shell, the sudo front-end
* escapes potential meta chars. We unescape non-spaces
* for sudoers matching and logging purposes.
*/
[7] for (to = user_args, av = NewArgv + 1; (from = *av); av++) {
while (*from) {
if (from[0] == '\\' && !isspace((unsigned char)from[1]))
from++;
*to++ = *from++;
}
*to++ = ' ';
}
*--to = '\0';
} else {
...
}
}
}
...
[8] if (!update_defaults(SETDEF_CMND, false)) {
[9] log_warningx(SLOG_SEND_MAIL|SLOG_NO_STDERR,
N_("problem with defaults entries"));
}
debug_return_int(ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment