Skip to content

Commit 2524090

Browse files
authored
Prefer inference-placeholder over taint-escape sql (#536)
1 parent ffb14f3 commit 2524090

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/QueryReflection/QueryReflection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $res
337337
}
338338

339339
if ($queryExpr instanceof Expr\CallLike) {
340-
if ('sql' === PhpDocUtil::matchTaintEscape($queryExpr, $scope)) {
341-
return '1';
342-
}
343-
344340
$placeholder = PhpDocUtil::matchInferencePlaceholder($queryExpr, $scope);
345341
if (null !== $placeholder) {
346342
return $placeholder;
347343
}
344+
345+
if ('sql' === PhpDocUtil::matchTaintEscape($queryExpr, $scope)) {
346+
return '1';
347+
}
348348
}
349349

350350
if ($queryExpr instanceof Concat) {

tests/rules/UnresolvableQueryMethodRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ public function testSyntaxErrorInQueryRule(): void
6565
],
6666
]);
6767
}
68+
69+
public function testBug536(): void
70+
{
71+
require_once __DIR__ . '/data/bug-536.php';
72+
73+
$this->analyse([__DIR__ . '/data/bug-536.php'], []);
74+
}
6875
}

tests/rules/data/bug-536.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug536;
4+
5+
use PDO;
6+
7+
function taintEscapedAndInferencePlaceholder(PDO $pdo, string $s)
8+
{
9+
$pdo->query('SELECT email, adaid FROM '. X::getTablePrefix('ada'), PDO::FETCH_ASSOC);
10+
}
11+
12+
class X {
13+
/**
14+
* Returns the table prefix.
15+
*
16+
* @return non-empty-string
17+
*
18+
* @phpstandba-inference-placeholder 'ada'
19+
* @psalm-taint-escape sql
20+
*/
21+
public static function getTablePrefix()
22+
{
23+
24+
}
25+
26+
}

0 commit comments

Comments
 (0)