Skip to content

Commit 5742f2b

Browse files
committed
Cherrypick: Inferred test-cases from Truncate sscanf/fscanf format string at NUL byte before counting placeholders
#5591
1 parent 6c8eddf commit 5742f2b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

tests/PHPStan/Rules/Functions/PrintfParametersRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,9 @@ public function testBug10260(): void
155155
$this->analyse([__DIR__ . '/data/bug-10260.php'], []);
156156
}
157157

158+
public function testBug14567(): void
159+
{
160+
$this->analyse([__DIR__ . '/data/bug-14567.php'], []);
161+
}
162+
158163
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug14567;
4+
5+
// NUL byte terminates sscanf/fscanf format string parsing
6+
// Placeholders after \0 should not be counted
7+
8+
// Only 1 placeholder active before NUL
9+
sscanf('123 456', "%d\0%d", $a);
10+
11+
// Only 1 placeholder active before NUL (fscanf)
12+
fscanf(STDIN, "%d\0%d", $a2);
13+
14+
// No placeholders after NUL
15+
sscanf('123', "\0%d");
16+
17+
// Multiple placeholders, NUL in middle
18+
sscanf('123 456 789', "%d %d\0%d", $b, $c);

0 commit comments

Comments
 (0)