From f130efd3915e5b13201daa7658df0fc2f81fd6e3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Sep 2023 11:34:11 +0200 Subject: [PATCH 1/3] Repro --- tests/rules/PdoStatementExecuteMethodRuleTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/rules/PdoStatementExecuteMethodRuleTest.php b/tests/rules/PdoStatementExecuteMethodRuleTest.php index dd93ad3da..9117894b3 100644 --- a/tests/rules/PdoStatementExecuteMethodRuleTest.php +++ b/tests/rules/PdoStatementExecuteMethodRuleTest.php @@ -125,6 +125,10 @@ public function testPlaceholderBug(): void 'Query expects 2-3 placeholders, but 1-3 values are given.', 42, ], + [ + 'Query expects 2 placeholders, but no values are given.', + 48, + ], ]); } } From 17d3ed19ca1d21aea17cd09bed67fe3f795c7adf Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Sep 2023 11:34:18 +0200 Subject: [PATCH 2/3] repro --- tests/rules/data/placeholder-bug.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/rules/data/placeholder-bug.php b/tests/rules/data/placeholder-bug.php index dae9861bb..4957f68ff 100644 --- a/tests/rules/data/placeholder-bug.php +++ b/tests/rules/data/placeholder-bug.php @@ -41,4 +41,10 @@ public function sometimesWrongNumberOfParameters(PDO $pdo, $vkFrom) $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ' . $fromCondition); $stmt->execute($values); } + + public function wrongMinBound(PDO $pdo) + { + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? '); + $stmt->execute([]); + } } From a7c96547f427ab40fbe5a1ceba71855f128a09c3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 29 Sep 2023 11:35:15 +0200 Subject: [PATCH 3/3] Update PlaceholderValidation.php --- src/QueryReflection/PlaceholderValidation.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/QueryReflection/PlaceholderValidation.php b/src/QueryReflection/PlaceholderValidation.php index 8200b933d..c8419de65 100644 --- a/src/QueryReflection/PlaceholderValidation.php +++ b/src/QueryReflection/PlaceholderValidation.php @@ -46,6 +46,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it } } + if ($minPlaceholderCount === PHP_INT_MAX) { + $minPlaceholderCount = 0; + } + yield from $this->validateUnnamedPlaceholders($parameters, $minPlaceholderCount, $maxPlaceholderCount); }