Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

execve bug



This is a bug which shows up in the NT port (based on 3.0.5).
It isn't in the NT-specific code, though, and I think would happen on
any system which doesn't support #!, so I'm sending it to zsh-workers.

If you have a script called 'dog' whose first line is '#!/bin/sh '
(i.e., has at least one space after the interpreter name), and
the OS doesn't support #!, zsh will wind up calling execve with
an argv of ("/bin/sh", "", "dog").  You get an error like
: : No such file or directory
or if you have multiple spaces,
 :  : Permission denied

Here's a patch to exec.c against 3.0.5 (or at least the version
in the zshsrc file for the NT distribution).

*** ../../zsh-orig/Src/exec.c   Wed May 19 16:16:26 1999
--- exec.c      Fri Jun 11 13:45:06 1999
***************
*** 180,187 ****
                if (execvebuf[0] == '#') {
                    if (execvebuf[1] == '!') {
                        for (t0 = 0; t0 != ct; t0++)
!                           if (execvebuf[t0] == '\n')
                                execvebuf[t0] = '\0';
                        execvebuf[POUNDBANGLIMIT] = '\0';
                        for (ptr = execvebuf + 2; *ptr && *ptr == ' '; ptr++);
                        for (ptr2 = ptr; *ptr && *ptr != ' '; ptr++);
--- 180,196 ----
                if (execvebuf[0] == '#') {
                    if (execvebuf[1] == '!') {
                        for (t0 = 0; t0 != ct; t0++)
!                           if (execvebuf[t0] == '\n') {
                                execvebuf[t0] = '\0';
+                               /* get rid of trailing spaces */
+                               for (--t0; t0 > 1; --t0) {
+                                 if (execvebuf[t0] == ' ') {
+                                   execvebuf[t0] = '\0';
+                                 } else {
+                                   break;
+                                 }
+                               }
+                           }
                        execvebuf[POUNDBANGLIMIT] = '\0';
                        for (ptr = execvebuf + 2; *ptr && *ptr == ' '; ptr++);
                        for (ptr2 = ptr; *ptr && *ptr != ' '; ptr++);




--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.



Messages sorted by: Reverse Date, Date, Thread, Author