Skip to content

Commit

Permalink
Use safer quoting for placeholders
Browse files Browse the repository at this point in the history
Switch to mysql_real_escape_string_quote for placeholder replacement,
allowing placeholders to be used when NO_BACKSLASH_ESCAPES is in effect.
  • Loading branch information
Matt Lawrence committed Jan 3, 2025
1 parent 49cbce2 commit e047fc9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ static char *parse_params(
if (!is_num)
{
*ptr++ = '\'';
ptr += mysql_real_escape_string(sock, ptr, valbuf, vallen);
ptr += mysql_real_escape_string_quote(sock, ptr, valbuf, vallen, '\'');
*ptr++ = '\'';
}
else
Expand Down
8 changes: 7 additions & 1 deletion t/17quote.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ my @results_ansi = (qw/ 'foo' 'foo\'bar' 'foo\\\\bar'/);
my @results_no_backlslash = (qw/ 'foo' 'foo''bar' 'foo\\bar'/);
my @results = (\@results_empty, \@results_ansi, \@results_no_backlslash);

plan tests => (@sqlmodes * @words * 2 + 1);
plan tests => (@sqlmodes * @words * 3 + 1);

while (my ($i, $sqlmode) = each @sqlmodes) {
$dbh->do("SET sql_mode=?", undef, $sqlmode eq "empty" ? "" : $sqlmode);
for my $j (0..@words-1) {
ok $dbh->quote($words[$j]);
cmp_ok($dbh->quote($words[$j]), "eq", $results[$i][$j], "$sqlmode $words[$j]");

is(
$dbh->selectrow_array('SELECT ?', undef, $words[$j]),
$words[$j],
"Round-tripped '$words[$j]' through a placeholder query"
);
}
}

Expand Down

0 comments on commit e047fc9

Please sign in to comment.