Date: Wed, 11 Mar 2026 15:01:30 +0100 From: Robert Clausecker <fuz@fuz.su> To: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= <des@freebsd.org> Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-branches@freebsd.org Subject: Re: git: 3d394a1da079 - stable/15 - system(3): Unwrap execve() Message-ID: <abF1ung7gxwotWVW@fuz.su> In-Reply-To: <69b16b36.275ef.6ffc5448@gitrepo.freebsd.org>
index | next in thread | previous in thread | raw e-mail
Hi des, Am Wed, Mar 11, 2026 at 01:16:38PM +0000 schrieb Dag-Erling Smørgrav: > The branch stable/15 has been updated by des: > > URL: https://cgit.FreeBSD.org/src/commit/?id=3d394a1da0798cbe8fa07bbc92dab14ad4c4fff1 > > commit 3d394a1da0798cbe8fa07bbc92dab14ad4c4fff1 > Author: Dag-Erling Smørgrav <des@FreeBSD.org> > AuthorDate: 2026-03-04 15:22:42 +0000 > Commit: Dag-Erling Smørgrav <des@FreeBSD.org> > CommitDate: 2026-03-11 13:16:00 +0000 > > 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 > > (cherry picked from commit 40e52e0edd038460a2a2aca017b3ac5a513fe37b) > --- > lib/libc/stdlib/system.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > 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 }; How about > + const char *argv[] = { "sh", "-c", command, NULL }; instead? > + 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 */ > /* Yours, Robert Clausecker -- () ascii ribbon campaign - for an encoding-agnostic world /\ - against html email - against proprietary attachmentshome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?abF1ung7gxwotWVW>
