ash: in tryexec(), ensure we don't try to run embedded scripts as applets
authorRon Yorston <rmy@pobox.com>
Thu, 1 Nov 2018 10:45:03 +0000 (11:45 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 1 Nov 2018 10:48:21 +0000 (11:48 +0100)
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c

index 58ecf6d2cecd506e1647e21e4fb7f810854268f9..19004aad849e454e1cf3f5af662e4d90de8c6e5c 100644 (file)
@@ -8017,6 +8017,10 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
 {
 #if ENABLE_FEATURE_SH_STANDALONE
        if (applet_no >= 0) {
+# if NUM_SCRIPTS > 0
+               if (applet_no >= NUM_APPLETS)
+                       goto run_script;
+# endif
                if (APPLET_IS_NOEXEC(applet_no)) {
                        clearenv();
                        while (*envp)
@@ -8039,7 +8043,11 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
 #else
        execve(cmd, argv, envp);
 #endif
+
        if (cmd != bb_busybox_exec_path && errno == ENOEXEC) {
+#if ENABLE_FEATURE_SH_STANDALONE && NUM_SCRIPTS > 0
+ run_script:
+#endif
                /* Run "cmd" as a shell script:
                 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
                 * "If the execve() function fails with ENOEXEC, the shell