[kaffe] Bug Report - Runtime.exec with environment strings crashes Kaffe

Warwick Hunter whunter@agile.tv
Fri, 04 Oct 2002 09:44:34 +1000


This is a multi-part message in MIME format.
--------------010108060002030000020401
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


If I call Runtime.exec with an array of strings for the
environment variables kaffe crashes.

Please find a patch against 1.0.7 attached. I can
redo it against CVS if you would prefer.

Warwick
-- 
Warwick Hunter                    Agile TV Corporation
Voice: +61 7 5584 5912            Fax: +61 7 5575 9550
mailto:whunter@agile.tv           http://www.agile.tv

--------------010108060002030000020401
Content-Type: text/plain;
 name="kaffe-1.0.7-execwithenv.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="kaffe-1.0.7-execwithenv.patch"

diff -Naur kaffe-1.0.7/libraries/clib/native/UNIXProcess.c kaffe-1.0.7.modified/libraries/clib/native/UNIXProcess.c
--- kaffe-1.0.7/libraries/clib/native/UNIXProcess.c	Tue Feb 29 05:31:27 2000
+++ kaffe-1.0.7.modified/libraries/clib/native/UNIXProcess.c	Thu Oct  3 04:41:23 2002
@@ -131,7 +131,7 @@
 
 		/* Search PATH variable */
 		ptr = NULL;
-		for (var = arge; var != NULL; var++) {
+		for (var = arge; var != NULL && *var != NULL; var++) {
 			if (strncmp (*var, "PATH=", 5) == 0) {
 				ptr = *var + 5;
 				break;
diff -Naur kaffe-1.0.7/test/regression/ExecTest.java kaffe-1.0.7.modified/test/regression/ExecTest.java
--- kaffe-1.0.7/test/regression/ExecTest.java	Fri Feb 12 13:51:08 1999
+++ kaffe-1.0.7.modified/test/regression/ExecTest.java	Thu Oct  3 12:14:23 2002
@@ -2,13 +2,16 @@
 {       
         public static void main ( String[] argv )
         {
+		String[] args = { "/bin/echo", "Hello World" };
+		String[] env  = { "A=B", "Hello=World" };
+                Runtime myRuntime = Runtime.getRuntime ();
+                Process myProcess = null;
+
                 for ( int i = 0; i < 2; i++ )
                 {
                         try
                         {
-				String[] args = { "/bin/echo", "Hello World" };
-                                Runtime myRuntime = Runtime.getRuntime ();
-                                Process myProcess = myRuntime.exec ( args );
+                                myProcess = myRuntime.exec ( args );
                                 try { myProcess.waitFor (); }
                                 catch ( InterruptedException e ) {}
 				System.out.println("Okay");
@@ -18,10 +21,22 @@
                                 System.out.println ( e );
                         }
                 }
+                try
+                {
+                        myProcess = myRuntime.exec ( args, env );
+                        try { myProcess.waitFor (); }
+                        catch ( InterruptedException e ) {}
+			System.out.println("Okay");
+                 }
+                 catch ( java.lang.Exception e )
+                 {
+                        System.out.println ( e );
+                 }
         }
 }
 
 /* Expected Output:
 Okay
 Okay
+Okay
 */

--------------010108060002030000020401--