Mail Archives: cygwin-developers/1998/11/20/11:36:57
On Fri, Nov 20, 1998 at 10:06:15PM +0900, Kazuhiro Fujieda wrote:
>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.
I agree that what cygwin is doing is not POSIX but we apparently
now have a number of people on the mailing list using this
"feature" so I don't believe that we can remove it without
generating a lot of confusion and dissatisfaction.
Does the patch below solve the problem?
-chris
Index: spawn.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/winsup/spawn.cc,v
retrieving revision 1.90
diff -u -p -r1.90 spawn.cc
--- spawn.cc 1998/11/19 23:31:00 1.90
+++ spawn.cc 1998/11/20 19:20:33
@@ -47,15 +47,12 @@ perhaps_suffix (const char *prog, char *
if (temp.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)
ext = NULL;
+ else if (temp.known_suffix)
+ ext = buf + (temp.known_suffix - temp.get_win32 ());
else
- {
- if (temp.known_suffix)
- ext = buf + (temp.known_suffix - temp.get_win32 ());
- else
- ext = strchr (temp.get_win32 (), '\0');
- }
+ ext = strchr (buf, '\0');
- debug_printf ("buf %s, suffix found '%s'", buf, ext ?: "(none)");
+ debug_printf ("buf %s, suffix found '%s'", buf, ext);
return ext;
}
@@ -63,7 +60,7 @@ perhaps_suffix (const char *prog, char *
suffixes to it. The win32-translated name is placed in 'buf'.
Any found suffix is returned in known_suffix.
- If the file is not found and !null_if_not_foudn then the win32 version
+ If the file is not found and !null_if_not_found then the win32 version
of name is placed in buf and returned. Otherwise the contents of buf
is undefined and NULL is returned. */
@@ -73,6 +70,7 @@ find_exec (const char *name, char *buf,
{
const char *suffix = "";
debug_printf ("find_exec (%s)", name);
+ char *retval = buf;
/* Check to see if file can be opened as is first.
Win32 systems always check . first, but PATH may not be set up to
@@ -119,15 +117,15 @@ errout:
/* Couldn't find anything in the given path.
Take the appropriate action based on null_if_not_found. */
if (null_if_notfound)
- buf = NULL;
+ retval = NULL;
else
strcpy (buf, path_conv (name).get_win32 ());
out:
debug_printf ("%s = find_exec (%s)", buf, name);
if (known_suffix)
- *known_suffix = suffix;
- return buf;
+ *known_suffix = suffix ?: strchr (buf, '\0');
+ return retval;
}
/* Utility for spawn_guts. */
- Raw text -