This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with exec("rundll32.exe shell32.dll...")


> > I think the two marked lines need to be made conditional on elts[i]
> > containing whitespace? (whitespace in this case is any of \t, \n, \r, \f -
> > this is taken from the parameterless constructor of StringTokenizer
> > http://java.sun.com/j2se/1.4.1/docs/api/java/util/StringTokenizer.html )
> 
> I did a little experiment with trying to get the
> *actual* command line passed to a program by Sun's JRE's
> Runtime.exec( ) using the Win32 GetCommandLine( ) function
> rather than the C runtime's argv array and it more or
> less confirms your hypothesis:
> 
>    The elements of the command line array are quoted *only if*
>    there's a space or a tab (\n, \r and \f are *not* "escaped").

Here's a little patch (against 3.3) that proposes to fix this 
(and PR 10880?) - I have tested this out on Win98 so far:

(The "String s = progarray[i]" is a vestigial remanant of a
variant with trim( ) - it turns out that at least JRE 1.4.1_01
does not trim( ) elements and we faithfully try to reproduce
this quirk.)

Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* java/lang/Win32Process.java (ConcreteProcess): Surround
	a command line element with quotes if it contains an
	embedded space or tab.

	* java/lang/natWin32Process.cc (startProcess): Do not
	surround command line elements with quotes here.

Index: java/lang/Win32Process.java
===================================================================
--- java/lang/Win32Process.java	2003-05-21 22:39:54.000000000 +0530
+++ java/lang/Win32Process.java	2003-05-21 23:01:19.000000000 +0530
@@ -68,4 +68,12 @@
     throws IOException
   {
+    for (int i = 0; i < progarray.length; i++)
+      {
+        String s = progarray[i];
+
+        if ( (s.indexOf (' ') >= 0) || (s.indexOf ('\t') >= 0))
+          progarray[i] = "\"" + s + "\"";
+      }
+
     startProcess (progarray, envp, dir);
   }
Index: java/lang/natWin32Process.cc
===================================================================
--- java/lang/natWin32Process.cc	2003-05-21 22:40:04.000000000 +0530
+++ java/lang/natWin32Process.cc	2003-05-21 22:48:34.000000000 +0530
@@ -137,5 +137,5 @@
 
   for (int i = 0; i < progarray->length; ++i)
-    cmdLineLen += (_Jv_GetStringUTFLength (elts[i]) + 3);
+    cmdLineLen += (_Jv_GetStringUTFLength (elts[i]) + 1);
 
   char *cmdLine = (char *) _Jv_Malloc (cmdLineLen + 1);
@@ -146,9 +146,7 @@
       if (i > 0)
         *cmdLineCurPos++ = ' ';
-      *cmdLineCurPos++ = '\"';
       jsize s = _Jv_GetStringUTFLength (elts[i]);
       _Jv_GetStringUTFRegion (elts[i], 0, s, cmdLineCurPos);
       cmdLineCurPos += s;
-      *cmdLineCurPos++ = '\"';
     }
   *cmdLineCurPos = '\0';


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]