Skip to content

Commit fbf0124

Browse files
committed
Add tests for socket file length check
1 parent e6b9385 commit fbf0124

2 files changed

+110
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
FPM: gh11066 - listen filename is too long for OS socket path limitation but starts anyway
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc"; ?>
6+
--FILE--
7+
<?php
8+
9+
require_once "tester.inc";
10+
$tempDir = sys_get_temp_dir();
11+
$socketFilePrefix = $tempDir . '/socket-file';
12+
$socketFile = $socketFilePrefix . '-that-is-too-long' . str_repeat('-0000', 18) . '.sock';
13+
$cfg = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
17+
[fpm_pool]
18+
listen = $socketFile
19+
pm = static
20+
pm.max_children = 1
21+
catch_workers_output = yes
22+
EOT;
23+
24+
$tester = new FPM\Tester($cfg);
25+
$tester->start();
26+
$tester->expectLogStartNotices();
27+
28+
$warningPattern = sprintf(
29+
'/\[pool fpm_pool\] cannot bind to UNIX socket \'%s\' as path is too long \(found length: %d, maximal length: \d+\), trying cut socket path instead \'.+\'/',
30+
preg_quote($socketFile, '/'),
31+
strlen($socketFile)
32+
);
33+
$tester->expectLogPattern($warningPattern, true);
34+
35+
$files = glob($socketFilePrefix . '*');
36+
37+
if ($files === []) {
38+
echo 'Socket files were not found.' . PHP_EOL;
39+
}
40+
41+
if ($socketFile === $files[0]) {
42+
// this means the socket file path length is not an issue (anymore). Might be not long enough
43+
echo 'Socket file is the same as configured.' . PHP_EOL;
44+
}
45+
46+
$tester->terminate();
47+
$tester->expectLogTerminatingNotices();
48+
$tester->close();
49+
?>
50+
Done
51+
--EXPECT--
52+
Done
53+
--CLEAN--
54+
<?php
55+
require_once "tester.inc";
56+
FPM\Tester::clean();
57+
58+
// cleanup socket file if php-fpm was not killed
59+
$tempDir = sys_get_temp_dir();
60+
$socketFilePrefix = $tempDir . '/socket-file';
61+
$socketFile = $socketFilePrefix . '-that-is-too-long' . str_repeat('-0000', 18) . '.sock';
62+
63+
if (is_file($socketFile)) {
64+
unlink($socketFile);
65+
}
66+
?>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
FPM: gh11066 - listen filename is too long for OS socket path limitation any fails configuration test
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc"; ?>
6+
--FILE--
7+
<?php
8+
9+
require_once "tester.inc";
10+
$tempDir = sys_get_temp_dir();
11+
$socketFilePrefix = $tempDir . '/socket-file';
12+
$socketFile = $socketFilePrefix . '-that-is-too-long' . str_repeat('-0000', 18) . '.sock';
13+
$cfg = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
17+
[fpm_pool]
18+
listen = $socketFile
19+
pm = static
20+
pm.max_children = 1
21+
catch_workers_output = yes
22+
EOT;
23+
24+
$tester = new FPM\Tester($cfg);
25+
$tester->testConfig();
26+
27+
$errorPattern = sprintf(
28+
'/\[pool fpm_pool\] cannot bind to UNIX socket \'%s\' as path is too long \(found length: %d, maximal length: \d+\)/',
29+
preg_quote($socketFile, '/'),
30+
strlen($socketFile)
31+
);
32+
$tester->expectLogPattern($errorPattern, true);
33+
$tester->expectLogPattern('/FPM initialization failed/', true);
34+
$tester->terminate();
35+
$tester->close();
36+
?>
37+
Done
38+
--EXPECT--
39+
Done
40+
--CLEAN--
41+
<?php
42+
require_once "tester.inc";
43+
FPM\Tester::clean();
44+
?>

0 commit comments

Comments
 (0)