in reply to Printing regular expression variable

Tangential observation: Pro forma untainting may be worse than none:

#!/usr/bin/perl -T use 5.016; my $regex = qr/^.*$/; # match anything, including an empty string my @strings = ('delete everything', 'overclock till cpu smokes', 'we ownz you exec(nasty code here)', ' ', '', ); untaint(@strings); sub untaint() { for my $elem(@strings) { if ( $elem =~ /$regex/ ) { say "Thank you, sucker. You are borked, really bad!"; }else{ say "Oh look, untainting did something more than merely al +low any-old-badstruff to pass untaint. string untainted was -|$elem|- +"; } } }

Execution produces:

C:\>untaint-bad.pl Thank you, sucker. You are borked, really bad! |delete everything|' passed. Thank you, sucker. You are borked, really bad! |overclock till cpu smokes|' passed. Thank you, sucker. You are borked, really bad! |we ownz you exec(nasty code here)|' passed. Thank you, sucker. You are borked, really bad! | |' passed. Thank you, sucker. You are borked, really bad! ||' passed.

If you didn't program your executable by toggling in binary, it wasn't really programming!

Replies are listed 'Best First'.
Re^2: Printing regular expression variable
by MattLG (Beadle) on May 28, 2013 at 13:20 UTC

    Err, sorry, what?

    MattLG

      "...my own CGI untainting library which uses regular expression variables like qr/^.*$/ to validate incoming data."
      Err, your example regex validates nothing; untaints nothing. If it's merely a simple example that occured to you for the purposes of your question, fine; if you believe it's doing something useful, you err.

      If you didn't program your executable by toggling in binary, it wasn't really programming!

        If it's merely a simple example that occured to you for the purposes of your question, fine

        I thought that was obvious, what would be the point of tainting the input and then just using ^.*$ on everything?

        MattLG