Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Re: Re: Trojan Horse? (taint mode)

by blakem (Monsignor)
on Nov 26, 2001 at 23:35 UTC ( #127605=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Trojan Horse? (taint mode)
in thread Trojan Horse? (taint mode)

I see no difference in the behavior of the following two lines:
$a = qq|${system("echo 'hello from system'")}\n|; $a = "${system(\"echo 'hello from system'\")}\n";
They both execute the 'echo' command which sends a message to your terminal and returns 0. My perl (5.00503 and 5.6.1 on unix) then complains that 0 is not a scalar ref and dies. Apparently your perl is casting the return value of 0 into a scalar ref to 0, and $a is assigned the value of $0, which happens to be the name of the script.

The book seems to imply that this behavior emulates what would happen if $a had come from user input. Fortunately that is not the case. If $a had come from STDIN, none of the above caveats would apply. Try it:

#!/usr/bin/perl -wT use strict; my $a = <STDIN>; chomp($a); print "$a";


Replies are listed 'Best First'.
Re:(lots of re:)Trojan Horse? (taint mode)
by cfreak (Chaplain) on Nov 27, 2001 at 01:32 UTC
    Opps must have foobared my test. You are correct
    $a = qq|${system("echo 'hello from system'")}\n|; $a = "${system(\"echo 'hello from system'\")}\n";

    do the same thing. Some how I had your example simply printing the string... hmmm

    Anyway I read the author to mean to not do this:
    $a = <stdin>; print "Some string with ${$a}";

    But as you stated I'm finding that doesn't work, which is very strange to me. It seems as though it should, and there could be really cool uses for it.

    That said, to get somewhat back on the orginal topic using taint mode is still a good idea, especially in CGI scripts. The trick is to learn what should be untainted and what doesn't have to be.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://127605]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-01-22 03:17 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (231 votes). Check out past polls.