Skip to content

Commit 3c183a8

Browse files
committed
Add tests for socket file length check
1 parent 5c4c9c6 commit 3c183a8

2 files changed

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

0 commit comments

Comments
 (0)