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

@@ -25,7 +25,7 @@
.nr BA @BAMAN@
.nr LC @LCMAN@
.nr PS @PSMAN@
.TH "SUDO" "@mansectsu@" "March 31, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
.TH "SUDO" "@mansectsu@" "April 2, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
.nh
.if n .ad l
.SH "NAME"
@@ -1140,7 +1140,9 @@ if no terminal is available or if the
option is specified.
.TP 17n
\fRSUDO_COMMAND\fR
Set to the command run by sudo.
Set to the command run by sudo, including command line arguments.
The command line arguments are truncated at 4096 characters to
prevent a potential execution error.
.TP 17n
\fRSUDO_EDITOR\fR
Default editor to use in

View File

@@ -24,7 +24,7 @@
.nr BA @BAMAN@
.nr LC @LCMAN@
.nr PS @PSMAN@
.Dd March 31, 2020
.Dd April 2, 2020
.Dt SUDO @mansectsu@
.Os Sudo @PACKAGE_VERSION@
.Sh NAME
@@ -1071,7 +1071,9 @@ if no terminal is available or if the
.Fl A
option is specified.
.It Ev SUDO_COMMAND
Set to the command run by sudo.
Set to the command run by sudo, including command line arguments.
The command line arguments are truncated at 4096 characters to
prevent a potential execution error.
.It Ev SUDO_EDITOR
Default editor to use in
.Fl e

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);