public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] posix: Fix return value of system if shell can not be executed [BZ #27053]
@ 2021-01-11 16:44 Adhemerval Zanella
0 siblings, 0 replies; only message in thread
From: Adhemerval Zanella @ 2021-01-11 16:44 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=42dda89dcb0407f6799dbfd0b9dab1529666ad51
commit 42dda89dcb0407f6799dbfd0b9dab1529666ad51
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Fri Dec 11 15:23:05 2020 -0300
posix: Fix return value of system if shell can not be executed [BZ #27053]
POSIX states that system returned code for failure to execute the shell
shall be as if the shell had terminated using _exit(127). This
behaviour was removed with 5fb7fc96350575.
Checked on x86_64-linux-gnu.
Diff:
---
stdlib/tst-system.c | 17 +++++++++++++++++
support/Makefile | 1 +
sysdeps/posix/system.c | 4 ++++
3 files changed, 22 insertions(+)
diff --git a/stdlib/tst-system.c b/stdlib/tst-system.c
index 95a2615d95..178808e048 100644
--- a/stdlib/tst-system.c
+++ b/stdlib/tst-system.c
@@ -26,6 +26,7 @@
#include <support/check.h>
#include <support/temp_file.h>
#include <support/support.h>
+#include <support/xunistd.h>
static char *tmpdir;
static long int namemax;
@@ -138,6 +139,22 @@ do_test (void)
support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
}
+ {
+ struct stat64 st;
+ xstat (_PATH_BSHELL, &st);
+ mode_t mode = st.st_mode;
+ xchmod (_PATH_BSHELL, mode & ~(S_IXUSR | S_IXGRP | S_IXOTH));
+
+ struct support_capture_subprocess result;
+ result = support_capture_subprocess (call_system,
+ &(struct args) {
+ "exit 1", 127, 0
+ });
+ support_capture_subprocess_check (&result, "system", 0, sc_allow_none);
+
+ xchmod (_PATH_BSHELL, st.st_mode);
+ }
+
TEST_COMPARE (system (""), 0);
return 0;
diff --git a/support/Makefile b/support/Makefile
index 62d6c6ddaa..bb9889efb4 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -91,6 +91,7 @@ libsupport-routines = \
xchroot \
xclock_gettime \
xclose \
+ xchmod \
xconnect \
xcopy_file_range \
xdlfcn \
diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c
index e53ec5f977..13c0662f90 100644
--- a/sysdeps/posix/system.c
+++ b/sysdeps/posix/system.c
@@ -175,6 +175,10 @@ do_system (const char *line)
__libc_cleanup_region_end (0);
#endif
}
+ else
+ /* POSIX states that failure to execute the shell should return
+ as if the shell had terminated using _exit(127). */
+ status = W_EXITCODE (127, 0);
DO_LOCK ();
if (SUB_REF () == 0)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-11 16:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 16:44 [glibc] posix: Fix return value of system if shell can not be executed [BZ #27053] Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).