Question

I am currently rewriting some custom perl-code used in the OTRS-ticketing-system, which is used to create SQL-like queries. Yes, there are probably better ways of escaping input, but let's not go into this...

$Param{PostMasterSearch} contains an email-adress like test'test@domain.tld (Note the ').

my $PostMasterSearch = $Param{PostMasterSearch};
$PostMasterSearch =~ s/'//gms;
$Self->{LogObject}->Log(
    Priority => 'error',
    Message => "XXXXX: $PostMasterSearch",
);
$SQLExt .= " $Field LIKE '$PostMasterSearch'";

So my expectation would be, that I'll find a log-message saying XXXXX: testtest@domain.tld and part of a SQL-query that goes like Email LIKE 'testtest@domain.tld'.

But in reality, I only get the log-message - the SQL-query-string is for whatever reason Email LIKE 'test'test@domain.tld'.

Screwing with the last line of the code to be like

$SQLExt .= " $Field LIKE '$PostMasterSearch' X";

doesn't make any sense - but returns the string Email LIKE 'testtest@domain.tld' X.

Any hints on why $PostMasterSearch is still containing that ' that should have been long gone? Or a hint on how to concatenate the $SQLExt with the '-less version of $PostMasterSearch?

Was it helpful?

Solution

OK, now this is the part where it gets embarrassing...

Turns out, that this script contains the very same code multiple times and executes it multiple times...

So the code posted above actually works and doesn't return any error (like it should). The error-message is caused by the next occurence of the code, that hasn't been patched yet.

tl;dr: I probably should trash that script and rewrite it from scratch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top