aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-03-04 15:22:42 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-03-04 15:22:42 +0000
commit40e52e0edd038460a2a2aca017b3ac5a513fe37b (patch)
tree8b6c9b4e6476a2f2110a32718198b4294af0097e
parent3d69387ece535fc33821d089aab241bfb9551d69 (diff)
system(3): Unwrap execve()
There is no need to call execl(), which will allocate an array and copy our arguments into it, when we can use a static array and call execve() directly. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55648
-rw-r--r--lib/libc/stdlib/system.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index 94f7460c9b68..a2f472502bfd 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -60,6 +60,8 @@ __libc_system(const char *command)
static struct sigaction ointact, oquitact;
struct sigaction ign;
sigset_t sigblock, osigblock;
+ char *argv[] = { "sh", "-c", __DECONST(char *, command), NULL };
+ extern char **environ;
int pstat = -1, serrno = 0;
pid_t pid;
@@ -101,7 +103,7 @@ __libc_system(const char *command)
/*
* Exec the command.
*/
- execl(_PATH_BSHELL, "sh", "-c", command, NULL);
+ _execve(_PATH_BSHELL, argv, environ);
_exit(127);
} else { /* parent */
/*