in reply to Re^2: Search 2 columns
in thread Search 2 columns

You are interpolating into a string and then using that string as a sprintf template. You are also not using placeholders, nor quoting things that go directly into the SQL.

Consider the following things that can go wrong when generating your SQL:

You can even do nastier stuff with a sprintf injection attack -- like change the value of variables in the script! So it is not just the SQL statement or database that might be affected.

Solutions/suggestions:

blokhead

Replies are listed 'Best First'.
Re^4: Search 2 columns
by roboticus (Chancellor) on Sep 22, 2007 at 16:35 UTC
    Yeah ... interpolation really makes a hash of things. ;^)

    %$search

    ...roboticus

      Well, I did try the following test before putting "%$search%" into the snippet suggestion in my own reply:
      perl -Mstrict -le 'my $s="blah"; print "%$s%"'
      which prints "%blah%". Putting a "%" in front of a scalar variable in a double-quoted string will not turn that variable into a hash ref.

      If the variable happens to already be a hash ref, then of course it will be interpolated as such, though not in a way that most folks would consider useful:

      perl -Mstrict -le 'my $s={foo=>"bar"}; print "%$s%"'
      prints something like "%HASH(0x1801380)%". It's only arrays (and array refs) that get interpolated into the list of values when placed inside double-quotes -- and only if the sigils are right:
      perl -Mstrict -le 'my %s=(foo => "bar"); print "%s"' %s perl -Mstrict -le 'my $s=[qw/foo bar/]; print "%$s%"' %ARRAY(0x1801380)% perl -Mstrict -le 'my $s=[qw/foo bar/]; print "@$s@"' foo bar@
        Ah, well, that's what I get when I comment without testing.... ;^(

        I knew I got smashed before with a %, I just thought it was like $ and always messed it up. Thanks for the clarification. Now I can use % in my messages again!

        ...roboticus