Truncate the command args at 4096 chars when formatting SUDO_COMMAND.

We have to limit the length of SUDO_COMMAND to avoid getting E2BIG
from execve(2) for very long argument vectors.
The command's environment also counts against the ARG_MAX limit.
Debian bug #596631
This commit is contained in:
Todd C. Miller
2020-04-02 13:01:58 -06:00
parent 9b8cb1a57a
commit 1d008b92f5
3 changed files with 14 additions and 5 deletions

View File

@@ -1109,7 +1109,12 @@ rebuild_env(void)
/* Add the SUDO_COMMAND envariable (cmnd + args). */
if (user_args) {
if (asprintf(&cp, "SUDO_COMMAND=%s %s", user_cmnd, user_args) == -1)
/*
* We limit user_args to 4096 bytes to avoid an execve() failure
* for very long argument vectors. The command's environment also
* counts against the ARG_MAX limit.
*/
if (asprintf(&cp, "SUDO_COMMAND=%s %.*s", user_cmnd, 4096, user_args) == -1)
goto bad;
if (sudo_putenv(cp, true, true) == -1) {
free(cp);