From: fujieda AT jaist DOT ac DOT jp (Kazuhiro Fujieda) Subject: script execution bug 20 Nov 1998 05:36:56 -0800 Message-ID: Mime-Version: 1.0 (generated by SEMI MIME-Edit 0.100 - "Shijima") Content-Type: text/plain; charset=US-ASCII To: cygwin32-developers AT cygnus DOT com I'm sorry for my poor English and poor patches every time, but... When a script file of which interpreter doesn't exist is executed in winsup-981116, a null pointer dereference occur at spawn.cc:288. It should be checked whether 'ext' is null after find_exec() is called at spawn.cc:358. In the first place, spawn_guts() doesn't need to call find_exec() because POSIX specified that the interpreter is executed by execve(). I believe spawn.cc:358 can be replaced as the following patch. --- ../winsup-981116/spawn.cc Sat Nov 14 07:52:06 1998 +++ spawn.cc Fri Nov 20 21:47:08 1998 @@ -355,7 +355,11 @@ * arg1 optional string * ptr end of string */ - find_exec (pgm, (char *) prog_arg1, "PATH=", 0, &ext); + if ((ext = perhaps_suffix (pgm, prog_arg1)) == NULL) + { + set_errno (ENOENT); + return -1; + } char *f = (char *) alloca (strlen (copy) + strlen (prog_arg) + strlen (real_path) + (ptr - arg1) + 7); strcpy (f, prog_arg1); Then, when a script of which interpreter is also a script is executed, the interpreter of the latter script is executed with odd arguments. For example, $ echo '#!/usr/local/bin/bar' > /usr/local/bin/foo $ echo '#!/sh' > /usr/local/bin/bar $ /usr/local/bin/foo /usr/local/bin/C:\usr\local\bin\bar: Can't open /usr/local/bin/C:\usr\local\bin\bar The following patch may solve this problem assuming that the previous patch is applied. --- spawn.cc- Fri Nov 20 21:48:52 1998 +++ spawn.cc Fri Nov 20 21:48:59 1998 @@ -362,7 +362,7 @@ } char *f = (char *) alloca (strlen (copy) + strlen (prog_arg) + strlen (real_path) + (ptr - arg1) + 7); - strcpy (f, prog_arg1); + strcpy (f, pgm); if (ptr == arg1) strcat (f, " "); else ____ | AIST Kazuhiro Fujieda | HOKURIKU School of Information Science o_/ 1990 Japan Advanced Institute of Science and Technology