Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by blakem (Monsignor)
on Nov 26, 2001 at 23:35 UTC ( [id://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";
</code>

-Blake

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found