Skip to content

Commit 6d9f97c

Browse files
Matt Lawrencedveeden
Matt Lawrence
authored andcommitted
Use safer quoting for placeholders
Switch to mysql_real_escape_string_quote for placeholder replacement, allowing placeholders to be used when NO_BACKSLASH_ESCAPES is in effect.
1 parent 49cbce2 commit 6d9f97c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

dbdimp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static char *parse_params(
636636
if (!is_num)
637637
{
638638
*ptr++ = '\'';
639-
ptr += mysql_real_escape_string(sock, ptr, valbuf, vallen);
639+
ptr += mysql_real_escape_string_quote(sock, ptr, valbuf, vallen, '\'');
640640
*ptr++ = '\'';
641641
}
642642
else

t/17quote.t

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ my @results_ansi = (qw/ 'foo' 'foo\'bar' 'foo\\\\bar'/);
2323
my @results_no_backlslash = (qw/ 'foo' 'foo''bar' 'foo\\bar'/);
2424
my @results = (\@results_empty, \@results_ansi, \@results_no_backlslash);
2525

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

2828
while (my ($i, $sqlmode) = each @sqlmodes) {
2929
$dbh->do("SET sql_mode=?", undef, $sqlmode eq "empty" ? "" : $sqlmode);
3030
for my $j (0..@words-1) {
3131
ok $dbh->quote($words[$j]);
3232
cmp_ok($dbh->quote($words[$j]), "eq", $results[$i][$j], "$sqlmode $words[$j]");
33+
34+
is(
35+
$dbh->selectrow_array('SELECT ?', undef, $words[$j]),
36+
$words[$j],
37+
"Round-tripped '$words[$j]' through a placeholder query"
38+
);
3339
}
3440
}
3541

0 commit comments

Comments
 (0)