]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
posix: Fix return value of system if shell can not be executed [BZ #27053]
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 11 Dec 2020 18:23:05 +0000 (15:23 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 11 Jan 2021 15:26:58 +0000 (12:26 -0300)
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.

stdlib/tst-system.c
support/Makefile
sysdeps/posix/system.c

index 95a2615d95159e6b0c9e52b7bbf6b1721257cb45..178808e048a9b3bc4668ad6001e1ec60f6d2b397 100644 (file)
@@ -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;
index 62d6c6ddaa8d757f671e32b14e08b4be47426d61..bb9889efb4be36303ace60dd6cc5202fc024a967 100644 (file)
@@ -91,6 +91,7 @@ libsupport-routines = \
   xchroot \
   xclock_gettime \
   xclose \
+  xchmod \
   xconnect \
   xcopy_file_range \
   xdlfcn \
index e53ec5f977e997eab587f917f9ce0bf9a1d1448c..13c0662f904264fdde01f8194728c8e1f4d47102 100644 (file)
@@ -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)