This is the mail archive of the java-prs@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]

libgcj/7570: Runtime.exec with null envp: child doesn't inherit parent env


>Number:         7570
>Category:       libgcj
>Synopsis:       Runtime.exec with null envp: child doesn't inherit parent env
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 10 14:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jesse Rosenstock
>Release:        3.3 20020810 (experimental)
>Organization:
>Environment:
System: Linux churchill 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-languages=c++,java --enable-threads=posix --enable-shared --prefix=/scratch/app/gcc --enable-hash-synchronization : (reconfigured) 
>Description:
	Runtime.exec is starting the child with an empty (except for PATH
        LD_LIBRARY_PATH) environment when passed null for the env argument.
        Sun's javadoc states: "If envp is null, the subprocess inherits the
        environment settings of the current process."
        The libjava javadoc states: "If the environment is null, the process
        inherits the environment of this process."
        This does not appear to be happening.
>How-To-Repeat:
	ExecEnv.java:

public class ExecEnv {
    private static void env(String[] envp) throws Exception {
        Process proc =
            Runtime.getRuntime().exec("/usr/bin/env", envp, null);
        int status = proc.waitFor();

        byte[] buf = new byte[proc.getInputStream().available()];
        proc.getInputStream().read(buf, 0, buf.length);

        System.out.write(buf, 0, buf.length);
    }

    public static void main(String[] args) throws Exception {
        System.out.println("Results with null env");
        env(null);
        System.out.println();

        System.out.println("Results with empty env");
        env(new String[0]);
        System.out.println();

        System.out.println("Results with foo env");
        env(new String[]{"foo=bar"});
        System.out.println();
    }
}

; javac ExecEnv.java
; java ExecEnv
Results with null env
STY=9173.pts-4.churchill
TERM=vt100
TERMCAP=SC|vt100|VT 100/ANSI X3.64 virtual terminal:\
        :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
        :cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
        :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
        :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
        :li#58:co#80:am:xn:xv:LP:sr=\EM:al=\E[L:AL=\E[%dL:\
        :cs=\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:dc=\E[P:DC=\E[%dP:\
        :im=\E[4h:ei=\E[4l:mi:IC=\E[%d@:ks=\E[?1h\E=:\
        :ke=\E[?1l\E>:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
        :us=\E[4m:ue=\E[24m:so=\E[3m:se=\E[23m:mb=\E[5m:\
        :md=\E[1m:mr=\E[7m:me=\E[m:ms:\
        :Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
        :vb=\Eg:G0:as=\E(0:ae=\E(B:\
        :ac=\140\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:\
        :po=\E[5i:pf=\E[4i:k0=\E[10~:k1=\EOP:k2=\EOQ:k3=\EOR:\
        :k4=\EOS:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:\
        :k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:F3=\E[25~:\
        :F4=\E[26~:F5=\E[28~:F6=\E[29~:F7=\E[31~:F8=\E[32~:\
        :F9=\E[33~:FA=\E[34~:kb=^H:K1=\EOw:K2=
Results with empty env

Results with foo env
foo=bar

; gij ExecEnv
Results with null env
PATH=/home/user/jmr/app/gdb/bin:/home/user/jmr/app/gcc/bin:/home/user/jmr/app/binutils/bin:/home/user/jmr/app/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin:/usr/local/java/bin:/usr/local/java/jre/bin:/usr/local/cad/bin:/usr/bin:/usr/sbin:/usr/X11R6/bin
LD_LIBRARY_PATH=/scratch/app/gcc/lib

Results with empty env
PATH=/home/user/jmr/app/gdb/bin:/home/user/jmr/app/gcc/bin:/home/user/jmr/app/binutils/bin:/home/user/jmr/app/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin:/usr/local/java/bin:/usr/local/java/jre/bin:/usr/local/cad/bin:/usr/bin:/usr/sbin:/usr/X11R6/bin
LD_LIBRARY_PATH=/scratch/app/gcc/lib

Results with foo env
foo=bar
PATH=/home/user/jmr/app/gdb/bin:/home/user/jmr/app/gcc/bin:/home/user/jmr/app/binutils/bin:/home/user/jmr/app/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin:/usr/local/java/bin:/usr/local/java/jre/bin:/usr/local/cad/bin:/usr/bin:/usr/sbin:/usr/X11R6/bin
LD_LIBRARY_PATH=/scratch/app/gcc/lib

>Fix:
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/Runtime.java,v
retrieving revision 1.11
diff -c -r1.11 Runtime.java
*** java/lang/Runtime.java      24 Jul 2002 23:17:39 -0000      1.11
--- java/lang/Runtime.java      10 Aug 2002 21:19:49 -0000
***************
*** 534,541 ****
      SecurityManager sm = securityManager; // Be thread-safe!
      if (sm != null)
        sm.checkExec(cmd[0]);
-     if (env == null)
-       env = new String[0];
      //XXX Should be:    return execInternal(cmd, env, dir);
      return execInternal(cmd, env);
    }
--- 534,539 ----
>Release-Note:
>Audit-Trail:
>Unformatted:


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