Check quoted function names like bare ones in the SQL mode
PostgreSQL accepts a function name in double quotes, so
SELECT "pg_read_file"('/etc/passwd') passed the forbidden-construct
check and SELECT "setval"('seq', 1) skipped the confirmation: the
patterns expect the name right before the parenthesis. The scanner now
unquotes a plain identifier when a parenthesis follows it, so a quoted
call is checked like the bare function name; quoted column names stay
as they are.
This commit is contained in:
@@ -122,7 +122,14 @@ class SqlGuard
|
||||
while ($i < $len) {
|
||||
$end = self::literalEnd($sql, $i);
|
||||
if ($end !== null) {
|
||||
$result .= $replaceLiterals ? ($sql[$i] === '"' ? '""' : "''") : substr($sql, $i, $end - $i);
|
||||
$literal = substr($sql, $i, $end - $i);
|
||||
if (preg_match('/^"([A-Za-z_][A-Za-z0-9_$]*)"$/', $literal, $m) && preg_match('/\G\s*\(/', $sql, $unused, 0, $end)) {
|
||||
// A quoted function name ("setval"(...)) calls the same
|
||||
// function as the bare word, so check it as one
|
||||
$result .= $m[1];
|
||||
} else {
|
||||
$result .= $replaceLiterals ? ($sql[$i] === '"' ? '""' : "''") : $literal;
|
||||
}
|
||||
$i = $end;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user