]> Savannah Git Hosting - gnulib.git/commitdiff
Don't execute scripts without '#!' marker through /bin/sh.
authorBruno Haible <bruno@clisp.org>
Wed, 23 Dec 2020 22:58:17 +0000 (23:58 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 04:31:53 +0000 (05:31 +0100)
This reflects the change done in glibc through
<https://sourceware.org/bugzilla/show_bug.cgi?id=13134> and
<https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d96de9634a334af16c0ac711074c15ac1762b23c>.

* lib/spawni.c (internal_function): Remove macro.
(script_execute): Remove function.
(__spawni): Don't invoke script_execute.
* lib/execute.c (execute): Disable the ENOEXEC handling.
* lib/spawn-pipe.c (create_pipe): Likewise.
* NEWS: Mention the change.

ChangeLog
NEWS
lib/execute.c
lib/spawn-pipe.c
lib/spawni.c

index 7d38a83d551ed38540e96f086977cbbd3249670d..b0d67daa595f23b2a3bb0d04dbfdd993e5900ca4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2020-12-23  Bruno Haible  <bruno@clisp.org>
+
+       Don't execute scripts without '#!' marker through /bin/sh.
+       This reflects the change done in glibc through
+       <https://sourceware.org/bugzilla/show_bug.cgi?id=13134> and
+       <https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d96de9634a334af16c0ac711074c15ac1762b23c>.
+       * lib/spawni.c (internal_function): Remove macro.
+       (script_execute): Remove function.
+       (__spawni): Don't invoke script_execute.
+       * lib/execute.c (execute): Disable the ENOEXEC handling.
+       * lib/spawn-pipe.c (create_pipe): Likewise.
+       * NEWS: Mention the change.
+
 2020-12-23  Bruno Haible  <bruno@clisp.org>
 
        posix_spawn[p]: Fix compilation error on Windows (regr. 2020-12-14).
diff --git a/NEWS b/NEWS
index 7679be06c52518c48c6e53589737e30e88257c43..c347ecd96df5cc8ac314ed2c6aa03064148763f6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,13 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2020-12-23  execute         These functions no longer execute scripts without
+            spawn-pipe      '#!' marker through /bin/sh. To execute such a
+            posix_spawn     script as a shell script, either add a '#!/bin/sh'
+            posix_spawnp    marker in the first line, or specify "/bin/sh" as
+                            the program to execute and the script as its first
+                            argument.
+
 2020-12-18  free            This module, obsoleted in 2008, is gone.
 
 2020-12-14  findprog-in     The function 'find_in_given_path' now takes a 3rd
index 41a2239c8d572c31e599a94cabdd4aafeeb9121d..38dd07bcef3283c6c945c8caee0dacb15fde579b 100644 (file)
@@ -191,6 +191,7 @@ execute (const char *progname,
       exitcode = spawnpvech (P_WAIT, prog_path, argv + 1,
                              (const char * const *) environ, directory,
                              stdin_handle, stdout_handle, stderr_handle);
+# if 0 /* Executing arbitrary files as shell scripts is unsecure.  */
       if (exitcode == -1 && errno == ENOEXEC)
         {
           /* prog is not a native executable.  Try to execute it as a
@@ -201,6 +202,7 @@ execute (const char *progname,
                                  (const char * const *) environ, directory,
                                  stdin_handle, stdout_handle, stderr_handle);
         }
+# endif
     }
   if (exitcode == -1)
     saved_errno = errno;
index d48352097b5ed944db3547d953319a3f36799a72..aedbcb2ae5ce6010d1e66dc14998a3677a94a4a2 100644 (file)
@@ -287,6 +287,7 @@ create_pipe (const char *progname,
       child = spawnpvech (P_NOWAIT, prog_path, argv + 1,
                           (const char * const *) environ, directory,
                           stdin_handle, stdout_handle, stderr_handle);
+#  if 0 /* Executing arbitrary files as shell scripts is unsecure.  */
       if (child == -1 && errno == ENOEXEC)
         {
           /* prog is not a native executable.  Try to execute it as a
@@ -297,6 +298,7 @@ create_pipe (const char *progname,
                               (const char * const *) environ, directory,
                               stdin_handle, stdout_handle, stderr_handle);
         }
+#  endif
     }
  failed:
   if (child == -1)
@@ -374,6 +376,7 @@ create_pipe (const char *progname,
     {
       child = _spawnvpe (P_NOWAIT, prog_path, argv + 1,
                          (const char **) environ);
+#  if 0 /* Executing arbitrary files as shell scripts is unsecure.  */
       if (child == -1 && errno == ENOEXEC)
         {
           /* prog is not a native executable.  Try to execute it as a
@@ -382,6 +385,7 @@ create_pipe (const char *progname,
           child = _spawnvpe (P_NOWAIT, argv[0], argv,
                              (const char **) environ);
         }
+#  endif
     }
   if (child == -1)
     saved_errno = errno;
index 06d98b473d721ec6f403c0c2d60896acb4126d91..182d13ff24ca2212f43b68570b8f05e39e472301 100644 (file)
@@ -75,9 +75,6 @@
 # define sigprocmask __sigprocmask
 # define strchrnul __strchrnul
 # define vfork __vfork
-#else
-# undef internal_function
-# define internal_function /* empty */
 #endif
 
 
@@ -105,36 +102,6 @@ __spawni (pid_t *pid, const char *file,
 #else
 
 
-/* The file is accessible but it is not an executable file.  Invoke
-   the shell to interpret it as a script.  */
-static void
-internal_function
-script_execute (const char *file, const char *const argv[],
-                const char *const envp[])
-{
-  /* Count the arguments.  */
-  int argc = 0;
-  while (argv[argc++])
-    ;
-
-  /* Construct an argument list for the shell.  */
-  {
-    const char **new_argv =
-      (const char **) alloca ((argc + 1) * sizeof (const char *));
-    new_argv[0] = _PATH_BSHELL;
-    new_argv[1] = file;
-    while (argc > 1)
-      {
-        new_argv[argc] = argv[argc - 1];
-        --argc;
-      }
-
-    /* Execute the shell.  */
-    execve (new_argv[0], (char * const *) new_argv, (char * const *) envp);
-  }
-}
-
-
 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
    Before running the process perform the actions described in FILE-ACTIONS. */
 int
@@ -307,9 +274,6 @@ __spawni (pid_t *pid, const char *file,
       /* The FILE parameter is actually a path.  */
       execve (file, (char * const *) argv, (char * const *) envp);
 
-      if (errno == ENOEXEC)
-        script_execute (file, argv, envp);
-
       /* Oh, oh.  'execve' returns.  This is bad.  */
       _exit (SPAWN_ERROR);
     }
@@ -358,9 +322,6 @@ __spawni (pid_t *pid, const char *file,
       /* Try to execute this name.  If it works, execv will not return.  */
       execve (startp, (char * const *) argv, (char * const *) envp);
 
-      if (errno == ENOEXEC)
-        script_execute (startp, argv, envp);
-
       switch (errno)
         {
         case EACCES: