Skip to content

Commit 59816b9

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents 2af3265 + 5a47f27 commit 59816b9

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ PHP NEWS
7070
. Fixed bug GH-16187 (Assertion failure in ext/reflection/php_reflection.c).
7171
(DanielEScherzer)
7272

73+
- SAPI:
74+
. Fixed bug GH-15395 (php-fpm: zend_mm_heap corrupted with cgi-fcgi request).
75+
(Jakub Zelenka, David Carlier)
76+
7377
- SimpleXML:
7478
. Fixed bug GH-15837 (Segmentation fault in ext/simplexml/simplexml.c).
7579
(nielsdos)

main/SAPI.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,15 @@ SAPI_API void sapi_deactivate_module(void)
509509
}
510510
if (SG(request_info).auth_user) {
511511
efree(SG(request_info).auth_user);
512+
SG(request_info).auth_user = NULL;
512513
}
513514
if (SG(request_info).auth_password) {
514515
efree(SG(request_info).auth_password);
516+
SG(request_info).auth_password = NULL;
515517
}
516518
if (SG(request_info).auth_digest) {
517519
efree(SG(request_info).auth_digest);
520+
SG(request_info).auth_digest = NULL;
518521
}
519522
if (SG(request_info).content_type_dup) {
520523
efree(SG(request_info).content_type_dup);

main/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,9 @@ PHPAPI int php_handle_auth_data(const char *auth)
26222622
if (pass) {
26232623
*pass++ = '\0';
26242624
SG(request_info).auth_user = estrndup(ZSTR_VAL(user), ZSTR_LEN(user));
2625-
SG(request_info).auth_password = estrdup(pass);
2625+
if (strlen(pass) > 0) {
2626+
SG(request_info).auth_password = estrdup(pass);
2627+
}
26262628
ret = 0;
26272629
}
26282630
zend_string_free(user);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
FPM: GH-15335 - PHP_AUTH shutdown use after free
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
log_level = notice
14+
[unconfined]
15+
listen = {{ADDR}}
16+
pm = static
17+
pm.max_children = 1
18+
catch_workers_output = yes
19+
php_admin_value[cgi.fix_pathinfo] = no
20+
EOT;
21+
22+
$code = <<<EOT
23+
<?php
24+
echo \$_SERVER["SCRIPT_NAME"] . "\n";
25+
echo \$_SERVER["SCRIPT_FILENAME"] . "\n";
26+
echo \$_SERVER["PHP_SELF"];
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
[$sourceFilePath, $scriptName] = $tester->createSourceFileAndScriptName();
31+
$tester->start();
32+
$tester->expectLogStartNotices();
33+
$tester
34+
->request(
35+
headers: [ "HTTP_AUTHORIZATION" => "Basic Zm9vOg==", "REQUEST_METHOD" => "GET"],
36+
uri: $scriptName,
37+
address: '{{ADDR}}',
38+
scriptFilename: __DIR__ . "/__unknown.php",
39+
scriptName: "/",
40+
)
41+
->expectStatus('404 Not Found');
42+
$tester
43+
->request(
44+
uri: $scriptName,
45+
address: '{{ADDR}}',
46+
params: [],
47+
);
48+
$tester->expectNoLogPattern("/zend_mm_heap corrupted/");
49+
$tester->terminate();
50+
$tester->expectLogTerminatingNotices();
51+
$tester->close();
52+
53+
?>
54+
Done
55+
--EXPECT--
56+
Done
57+
--CLEAN--
58+
<?php
59+
require_once "tester.inc";
60+
FPM\Tester::clean();
61+
?>

sapi/fpm/tests/tester.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ class Tester
848848
bool $expectError = false,
849849
int $readLimit = -1,
850850
int $writeDelay = 0,
851+
array $params = null,
851852
): Response {
852853
if ($this->hasError()) {
853854
return $this->createResponse(expectInvalid: true);
@@ -857,7 +858,7 @@ class Tester
857858
$stdin = $this->parseStdin($stdin, $headers);
858859
}
859860

860-
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename, $scriptName, $stdin);
861+
$params = $params ?? $this->getRequestParams($query, $headers, $uri, $scriptFilename, $scriptName, $stdin);
861862
$this->trace('Request params', $params);
862863

863864
try {

0 commit comments

Comments
 (0)