|
| 1 | +--TEST-- |
| 2 | +FPM: GH-24661 - Pools with different disable_functions must not share cached scripts |
| 3 | +--EXTENSIONS-- |
| 4 | +opcache |
| 5 | +--SKIPIF-- |
| 6 | +<?php include "skipif.inc"; ?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | + |
| 10 | +require_once "tester.inc"; |
| 11 | + |
| 12 | +$cfg = <<<EOT |
| 13 | +[global] |
| 14 | +error_log = {{FILE:LOG}} |
| 15 | +[unrestricted] |
| 16 | +listen = {{ADDR[unrestricted]}} |
| 17 | +pm = static |
| 18 | +pm.max_children = 1 |
| 19 | +[restricted] |
| 20 | +listen = {{ADDR[restricted]}} |
| 21 | +pm = static |
| 22 | +pm.max_children = 1 |
| 23 | +php_admin_value[disable_functions] = zend_version |
| 24 | +EOT; |
| 25 | + |
| 26 | +/* Disabling zend_version() moves the functions registered after it in the |
| 27 | + * function table, var_export() among them. */ |
| 28 | +$code = <<<'EOT' |
| 29 | +<?php |
| 30 | +function zend_version_or_error(): string { |
| 31 | + try { |
| 32 | + return gettype(zend_version()); |
| 33 | + } catch (Error $e) { |
| 34 | + return $e->getMessage(); |
| 35 | + } |
| 36 | +} |
| 37 | +var_dump(is_array(opcache_get_status(false))); |
| 38 | +echo var_export(true, true), "\n"; |
| 39 | +var_dump(function_exists('zend_version')); |
| 40 | +echo zend_version_or_error(), "\n"; |
| 41 | +EOT; |
| 42 | + |
| 43 | +$expected = [ |
| 44 | + 'unrestricted' => ['bool(true)', 'true', 'bool(true)', 'string'], |
| 45 | + 'restricted' => ['bool(true)', 'true', 'bool(false)', 'Call to undefined function zend_version()'], |
| 46 | +]; |
| 47 | + |
| 48 | +$opcache = ini_get('extension_dir') . DIRECTORY_SEPARATOR . 'opcache.' . PHP_SHLIB_SUFFIX; |
| 49 | +$extraArgs = is_file($opcache) ? ['-dzend_extension=' . $opcache] : []; |
| 50 | + |
| 51 | +function remove_file_cache(string $dir): void { |
| 52 | + if (!is_dir($dir)) { |
| 53 | + return; |
| 54 | + } |
| 55 | + $it = new RecursiveIteratorIterator( |
| 56 | + new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS), |
| 57 | + RecursiveIteratorIterator::CHILD_FIRST |
| 58 | + ); |
| 59 | + foreach ($it as $file) { |
| 60 | + $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname()); |
| 61 | + } |
| 62 | + rmdir($dir); |
| 63 | +} |
| 64 | + |
| 65 | +$fileCache = __DIR__ . '/gh24661-file-cache'; |
| 66 | +$caches = [ |
| 67 | + [], |
| 68 | + ['opcache.file_cache' => $fileCache, 'opcache.file_cache_only' => '1'], |
| 69 | +]; |
| 70 | + |
| 71 | +foreach ($caches as $iniEntries) { |
| 72 | + /* The pool that compiles the script first must not matter. */ |
| 73 | + foreach ([['unrestricted', 'restricted'], ['restricted', 'unrestricted']] as $pools) { |
| 74 | + if ($iniEntries) { |
| 75 | + remove_file_cache($fileCache); |
| 76 | + mkdir($fileCache); |
| 77 | + } |
| 78 | + $tester = new FPM\Tester($cfg, $code); |
| 79 | + $tester->start($extraArgs, iniEntries: $iniEntries + ['opcache.file_update_protection' => '0']); |
| 80 | + $tester->expectLogStartNotices(); |
| 81 | + foreach ([...$pools, ...$pools] as $pool) { |
| 82 | + $tester->request(address: "{{ADDR[$pool]}}")->expectBody($expected[$pool]); |
| 83 | + } |
| 84 | + $tester->terminate(); |
| 85 | + $tester->expectLogTerminatingNotices(); |
| 86 | + $tester->close(); |
| 87 | + if ($iniEntries) { |
| 88 | + /* One system ID directory for each function table. */ |
| 89 | + $systemIds = glob($fileCache . '/*', GLOB_ONLYDIR); |
| 90 | + if (count($systemIds) !== 2) { |
| 91 | + echo "File cache directories: ", count($systemIds), "\n"; |
| 92 | + } |
| 93 | + remove_file_cache($fileCache); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +?> |
| 99 | +Done |
| 100 | +--EXPECT-- |
| 101 | +Done |
| 102 | +--CLEAN-- |
| 103 | +<?php |
| 104 | +require_once "tester.inc"; |
| 105 | +FPM\Tester::clean(); |
| 106 | +$fileCache = __DIR__ . '/gh24661-file-cache'; |
| 107 | +if (is_dir($fileCache)) { |
| 108 | + $it = new RecursiveIteratorIterator( |
| 109 | + new RecursiveDirectoryIterator($fileCache, FilesystemIterator::SKIP_DOTS), |
| 110 | + RecursiveIteratorIterator::CHILD_FIRST |
| 111 | + ); |
| 112 | + foreach ($it as $file) { |
| 113 | + $file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname()); |
| 114 | + } |
| 115 | + rmdir($fileCache); |
| 116 | +} |
| 117 | +?> |
0 commit comments