Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4635001

(process) PATH is searched relative to execution directory on Unix

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs

      Name: nt126004 Date: 02/07/2002


      FULL PRODUCT VERSION :
      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

      FULL OPERATING SYSTEM VERSION : Linux gescher 2.4.17-PMC-SMP
      #4 SMP Thu Jan 31 14:23:30 CET 2002 i686 unknown


      A DESCRIPTION OF THE PROBLEM :
      When Runtime.exec(cmd, env, execdir) finds cmd in any
      directory listed in $PATH, it prepends the directory to the
      command name. Then, if I have "." in my $PATH and the
      current directory contains an executable called cmd, then
      cmd becomes ./cmd.

      As Runtime.exec changes to execdir (before executing ./cmd),
      if there is also a file called cmd in execdir, this file
      will be executed -- and not the one previously found in my
      $PATH.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Be sure that . is the first directory in your PATH

      2.In the current directory do:
         mkdir foo; echo #\!/bin/sh > scr; echo echo hi >> scr;
      echo #\!/bin/sh > foo/scr; echo echo ciao >> foo/scr; chmod
      u+x scr; chmod u+x foo/scr

      3.Run in the current directory the program given below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      expected: hi should be printed
      actual result: ciao is printed

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      public class T {
        public static void main(String[] args) throws Exception {
            String s;
            Process p = Runtime.getRuntime().exec("scr", null, new File("foo"));
            p.waitFor();
            BufferedReader r = new BufferedReader(new
      InputStreamReader(p.getInputStream()));
            while ((s=r.readLine()) != null) System.out.println(s);
            System.out.println(p.exitValue());
        }
      }

      ---------- END SOURCE ----------
      (Review ID: 139304)
      ======================================================================

            martin Martin Buchholz
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: