Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi, I have a command in my perl script.
system "command1 img.g3 | command2 > img.ps";
now, I add the taint mode...
=> Insecure $ENV{PATH} while running with -T
;o((

I try :

system "command1 img.g3 > img.pbm"; system "command2 img.pbm > img.ps"; system "command1", "img.g3" > img.pbm;
etc... no good Can you help me? thank you anne

Replies are listed 'Best First'.
Re: perl and taint mode
by borisz (Canon) on Jan 01, 2005 at 23:06 UTC
    Read perldoc perlsec. In short set PATH to a known value.
    $ENV{PATH}=''; system '/path/to/command img.g3 | /path/to/command2 img.pbm > img.ps' +;
    Boris
      now, I have Insecure dependency in system while running with -T grrrr... I try system "command1", "img.g3" > "img.pbm"; (command1 = /path/to/command and img.g3 = /path/to/img.g3 and img.pbm = /path/to/img.pbm) => Argument "/home/e-smith/files/ibays/fax-voice1/html/fax/tmp/3145.f..." isn't numeric in numeric gt (>) at /home/e-smith/files/ibays/fax-voice 1/cgi-bin/fax/nph-vf-pdf.cgi line 653. I want to write in img.pbm!!! It is not a numerical operation ;o) anne
        You are now using the list form of system, which means no shell will be used (which is good). However, redirection like ">" is done by the shell, so you can't do it like that. (you can use a pipe open instead and write the file yourself, or use backticks, or do the fork/exec yourself so you can first open stdout to a file. Or go back to using the shell, but in a safe way).

        Also notice that the insecure PATH complaint was about how the program gets looked up, and has nothing to do with the targetfile. You don't have to give that an absolute path (unless what your working directory is is untrusted too of course).

        Now carefully read your error message. It's not complaining about an insecure dependency, but that you are comparing string "img.g3" to "img.pbm". Always start by assuming perl knows what it's talking about, however sure you are that you know better. There's always a reason for the messages you get.

Re: perl and taint mode
by ikegami (Patriarch) on Jan 02, 2005 at 05:04 UTC
    ">" requires the use of a shell, and thus, isn't taint-safe. You could use system("/bin/sh", ...), but be very careful to validate the strings you pass as arguments to the shell. Alternatively, you could use fork+exec with IO handles manipulations (with or without the help of IPC::Open3 or IPC::Run).
      I seek a program with IPC-Open3. Just a small example... thank you anne