Skip to content

Commit 301cf48

Browse files
theodorejbstaabm
authored andcommitted
Respect sys_temp_dir from the parent process (#5390)
1 parent c191613 commit 301cf48

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ jobs:
457457
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv test.php 2>&1)
458458
echo "$OUTPUT"
459459
../bashunit -a contains 'Parallel processing scheduler' "$OUTPUT"
460+
- script: |
461+
cd e2e/bug-14093
462+
# Use a relative sys_temp_dir so the value starts with a letter (not /), just like Windows
463+
# paths starting with a drive letter. If the sys_temp_dir value isn't correctly quoted,
464+
# PHP evaluates ~ as a bitwise NOT rather than a literal character, truncating the path.
465+
mkdir tmp~1
466+
php -d "sys_temp_dir='tmp~1'" ../../bin/phpstan analyze
467+
if [ -d tmp ]; then
468+
echo "FAIL: tmp was created by a worker, meaning sys_temp_dir='tmp~1' was incorrectly evaluated to 'tmp'"
469+
exit 1
470+
fi
460471
461472
steps:
462473
- name: Harden the runner (Audit all outbound calls)

e2e/bug-14093/phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- test.php

e2e/bug-14093/test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php declare(strict_types=1);
2+
3+
function add(int $a, int $b): int
4+
{
5+
return $a + $b;
6+
}

src/Process/ProcessHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use function is_bool;
1212
use function php_ini_loaded_file;
1313
use function sprintf;
14+
use function sys_get_temp_dir;
1415
use const PHP_BINARY;
1516

1617
final class ProcessHelper
@@ -32,6 +33,9 @@ public static function getWorkerCommand(
3233

3334
$processCommandArray = [
3435
$phpCmd,
36+
'-d',
37+
// quote value so PHP will parse it as a string when the path contains a bitwise operator like ~
38+
'sys_temp_dir=' . escapeshellarg("'" . sys_get_temp_dir() . "'"),
3539
];
3640

3741
if ($input->getOption('memory-limit') === null) {

0 commit comments

Comments
 (0)