Fw: [Mono-list] Process.Start patch

Jerome Laban jlaban@wanadoo.fr
Fri, 28 Feb 2003 01:54:43 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0550_01C2DECC.5D1E32B0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0551_01C2DECC.5D1E32B0"


------=_NextPart_001_0551_01C2DECC.5D1E32B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Actually I've found an other bug at the same location. If the end of the =
specified path was a directory with the x flag, a process was =
incorrectly started.

The new patch fixes this issue. (replaces the previous mail's patch, I =
hope it is not too late :p )

Jerome.
  ----- Original Message -----=20
  From: Jerome Laban=20
  To: mono-list@ximian.com=20
  Sent: Friday, February 28, 2003 12:36 AM
  Subject: [Mono-list] Process.Start patch


  Hi there,

      Here is a fix for the overloads of =
System.Diagnostics.Process.Start, the method CreateProcess in =
processes.c was not checking for the executable validity when called =
with a absolute path. There were also two uninitialized variables that =
now are set to NULL. (would have lead to multiple frees in this context)

  Could someone commit it if ok ?

  An other thing, a null reference should not be sent when the =
executable is not found. How should this be addressed ?

  Jerome.
------=_NextPart_001_0551_01C2DECC.5D1E32B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Actually I've found an other bug at the same =
location. If the=20
end of the specified path was a directory with the x flag, a process was =

incorrectly started.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The new patch fixes this issue. (replaces the =
previous mail's=20
patch,&nbsp;I hope it is not too late :p )</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Jerome.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Djlaban@wanadoo.fr href=3D"mailto:jlaban@wanadoo.fr">Jerome =
Laban</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dmono-list@ximian.com=20
  href=3D"mailto:mono-list@ximian.com">mono-list@ximian.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, February 28, 2003 =
12:36=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Mono-list] =
Process.Start=20
  patch</DIV>
  <DIV><BR></DIV>
  <DIV><FONT size=3D2>Hi there,</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; Here is a fix for the overloads =
of <FONT=20
  face=3D"Courier New">System.Diagnostics.Process.Start</FONT><FONT =
face=3DTahoma>,=20
  the method <FONT face=3D"Courier New">CreateProcess</FONT> in =
</FONT><FONT=20
  face=3D"Courier New">processes.c </FONT><FONT face=3DTahoma>was not =
checking for=20
  the executable validity when called with a absolute path. There were =
also two=20
  uninitialized variables that now are set to NULL. (would have lead to =
multiple=20
  frees in this context)</FONT></FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>Could someone commit it if ok ?</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>An other thing, a null reference should not be =
sent when the=20
  executable is not found. How should this be addressed ?</FONT></DIV>
  <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2>Jerome.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_001_0551_01C2DECC.5D1E32B0--

------=_NextPart_000_0550_01C2DECC.5D1E32B0
Content-Type: application/octet-stream;
	name="processes.c.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="processes.c.diff"

Index: mono/io-layer/processes.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mono/mono/io-layer/processes.c,v=0A=
retrieving revision 1.11=0A=
diff -u -r1.11 processes.c=0A=
--- mono/io-layer/processes.c	21 Feb 2003 13:22:10 -0000	1.11=0A=
+++ mono/io-layer/processes.c	28 Feb 2003 00:42:12 -0000=0A=
@@ -20,6 +20,7 @@=0A=
 #include <errno.h>=0A=
 #include <sys/types.h>=0A=
 #include <unistd.h>=0A=
+#include <sys/stat.h>=0A=
 =0A=
 #include <mono/io-layer/wapi.h>=0A=
 #include <mono/io-layer/unicode.h>=0A=
@@ -89,13 +90,14 @@=0A=
 			WapiStartupInfo *startup,=0A=
 			WapiProcessInformation *process_info)=0A=
 {=0A=
-	gchar *cmd=3DNULL, *prog, *full_prog, *args=3DNULL, =
*args_after_prog=3DNULL, *dir=3DNULL;=0A=
+	gchar *cmd=3DNULL, *prog =3D NULL, *full_prog =3D NULL, *args=3DNULL, =
*args_after_prog=3DNULL, *dir=3DNULL;=0A=
 	guint32 env=3D0, stored_dir=3D0, stored_prog=3D0, i;=0A=
 	gboolean ret=3DFALSE;=0A=
 	gpointer stdin_handle, stdout_handle, stderr_handle;=0A=
 	guint32 pid, tid;=0A=
 	gpointer process_handle, thread_handle;=0A=
-	=0A=
+	struct stat file_stat;=0A=
+=0A=
 	mono_once (&process_ops_once, process_ops_init);=0A=
 	=0A=
 	/* appname and cmdline specify the executable and its args:=0A=
@@ -328,6 +330,19 @@=0A=
 		if(token[0]=3D=3D'/') {=0A=
 			/* Assume full path given */=0A=
 			prog=3Dg_strdup (token);=0A=
+=0A=
+			ret=3Dstat (prog, &file_stat);=0A=
+			=0A=
+			/* Executable existing ? */=0A=
+			if(access (prog, X_OK) !=3D 0 || (ret =3D=3D 0 && =
S_ISDIR(file_stat.st_mode)) ) {=0A=
+				g_free (prog);=0A=
+#ifdef DEBUG=0A=
+				g_message (G_GNUC_PRETTY_FUNCTION ": Couldn't find executable %s", =
token);=0A=
+#endif=0A=
+				g_free (token);=0A=
+				goto cleanup;=0A=
+			}=0A=
+=0A=
 		} else {=0A=
 			char *curdir=3Dg_get_current_dir ();=0A=
 =0A=
@@ -340,10 +355,12 @@=0A=
 			prog=3Dg_strdup_printf ("%s/%s", curdir, token);=0A=
 			g_free (curdir);=0A=
 =0A=
+			ret=3Dstat (prog, &file_stat);=0A=
+=0A=
 			/* I assume X_OK is the criterion to use,=0A=
 			 * rather than F_OK=0A=
 			 */=0A=
-			if(access (prog, X_OK)!=3D0) {=0A=
+			if(access(prog, X_OK) !=3D 0 || (ret =3D=3D 0 && =
S_ISDIR(file_stat.st_mode)) ) {=0A=
 				g_free (prog);=0A=
 				prog=3Dg_find_program_in_path (token);=0A=
 				if(prog=3D=3DNULL) {=0A=

------=_NextPart_000_0550_01C2DECC.5D1E32B0--