Skip to content

Commit 339ae0f

Browse files
committed
Avoid accessing undefined variables in run-tests.php
The $php_cgi and $phpdbg cases here are definitely real bugs, and caused the script to bail out under certain ini settings. The other paths may actually be unreachable in practice, but were highlighted by PhpStorm. Writing to php://stdin apparently works fine, but doesn't make any sense, and was probably a mistake due to bad variable naming.
1 parent ab67b52 commit 339ae0f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

run-tests.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,12 @@ function save_or_mail_results(): void
935935
$PHP_FAILED_TESTS, $php, $output_file;
936936

937937
/* We got failed Tests, offer the user to send an e-mail to QA team, unless NO_INTERACTION is set */
938-
if (!getenv('NO_INTERACTION') && !TRAVIS_CI) {
939-
$fp = fopen("php://stdin", "r+");
938+
if (getenv('NO_INTERACTION') || TRAVIS_CI) {
939+
$stdin = null;
940+
$user_input = '';
941+
}
942+
else {
943+
$stdin = fopen("php://stdin", "r");
940944
if ($sum_results['FAILED'] || $sum_results['BORKED'] || $sum_results['WARNED'] || $sum_results['LEAKED']) {
941945
echo "\nYou may have found a problem in PHP.";
942946
}
@@ -948,7 +952,7 @@ function save_or_mail_results(): void
948952
echo "Do you want to send this report now? [Yns]: ";
949953
flush();
950954

951-
$user_input = fgets($fp, 10);
955+
$user_input = fgets($stdin, 10);
952956
$just_save_results = (!empty($user_input) && strtolower($user_input[0]) === 's');
953957
}
954958

@@ -967,10 +971,12 @@ function save_or_mail_results(): void
967971
/* Ask the user to provide an email address, so that QA team can contact the user */
968972
if (TRAVIS_CI) {
969973
$user_email = 'travis at php dot net';
974+
} elseif ($stdin === null) {
975+
$user_email = null;
970976
} elseif (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) == 0) {
971977
echo "\nPlease enter your email address.\n(Your address will be mangled so that it will not go out on any\nmailinglist in plain text): ";
972978
flush();
973-
$user_email = trim(fgets($fp, 1024));
979+
$user_email = trim(fgets($stdin, 1024));
974980
$user_email = str_replace("@", " at ", str_replace(".", " dot ", $user_email));
975981
}
976982

@@ -1052,8 +1058,8 @@ function save_or_mail_results(): void
10521058

10531059
echo "Please send " . $output_file . " to " . PHP_QA_EMAIL . " manually, thank you.\n";
10541060
} elseif (!getenv('NO_INTERACTION') && !TRAVIS_CI) {
1055-
fwrite($fp, "\nThank you for helping to make PHP better.\n");
1056-
fclose($fp);
1061+
echo "\nThank you for helping to make PHP better.\n";
1062+
fclose($stdin);
10571063
}
10581064
}
10591065
}
@@ -1887,13 +1893,8 @@ function run_test(string $php, $file, array $env): string
18871893
$org_file = $file;
18881894
$orig_php = $php;
18891895

1890-
if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) {
1891-
$php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'];
1892-
}
1893-
1894-
if (isset($env['TEST_PHPDBG_EXECUTABLE'])) {
1895-
$phpdbg = $env['TEST_PHPDBG_EXECUTABLE'];
1896-
}
1896+
$php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'] ?? null;
1897+
$phpdbg = $env['TEST_PHPDBG_EXECUTABLE'] ?? null;
18971898

18981899
if (is_array($file)) {
18991900
$file = $file[0];
@@ -2574,6 +2575,8 @@ function run_test(string $php, $file, array $env): string
25742575
}
25752576
}
25762577

2578+
$wanted_headers = null;
2579+
$output_headers = null;
25772580
$failed_headers = false;
25782581

25792582
if ($test->hasSection('EXPECTHEADERS')) {
@@ -2732,6 +2735,8 @@ function run_test(string $php, $file, array $env): string
27322735
}
27332736
}
27342737

2738+
$restype = [];
2739+
27352740
if ($leaked) {
27362741
$restype[] = $test->hasSection('XLEAK') ?
27372742
'XLEAK' : 'LEAK';

0 commit comments

Comments
 (0)