Skip to content

Commit cd8312e

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: Zend: Include frameless functions in the system id
2 parents 9696705 + 4e5516a commit cd8312e

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

‎Zend/zend_API.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "zend_enum.h"
3535
#include "zend_object_handlers.h"
3636
#include "zend_observer.h"
37+
#include "zend_system_id.h"
3738

3839
#include <stdarg.h>
3940

@@ -3222,6 +3223,7 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
32223223
}
32233224
zend_flf_handlers[zend_flf_count] = flf_info->handler;
32243225
zend_flf_functions[zend_flf_count] = (zend_function *)reg_function;
3226+
zend_add_system_entropy("frameless", ZSTR_VAL(reg_function->function_name), &flf_info->num_args, sizeof(flf_info->num_args));
32253227
zend_flf_count++;
32263228
flf_info++;
32273229
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
--TEST--
2+
opcache file cache must not reuse frameless function indices across extension sets
3+
--EXTENSIONS--
4+
opcache
5+
--SKIPIF--
6+
<?php
7+
$dl_test = PHP_OS_FAMILY === 'Windows' ? 'php_dl_test.dll' : 'dl_test.so';
8+
if (!file_exists(ini_get('extension_dir') . DIRECTORY_SEPARATOR . $dl_test)) {
9+
die('skip dl_test extension is not built');
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
$cache = __DIR__ . DIRECTORY_SEPARATOR . 'file_cache_frameless_handler';
15+
$script = $cache . DIRECTORY_SEPARATOR . 'call.php';
16+
mkdir($cache);
17+
file_put_contents($script, <<<'PHP'
18+
<?php
19+
if (isset($argv[1])) {
20+
dl('dl_test');
21+
}
22+
try {
23+
var_dump(dl_test_frameless(7));
24+
} catch (Error $e) {
25+
echo $e::class, ": ", $e->getMessage(), "\n";
26+
}
27+
PHP);
28+
29+
function run(string $cache, array $args): void {
30+
$ext = ini_get('extension_dir');
31+
$opcache = PHP_OS_FAMILY === 'Windows' ? 'php_opcache.dll' : 'opcache.so';
32+
$cmd = [PHP_BINARY, '-n', '-d', 'extension_dir="' . $ext . '"'];
33+
if (file_exists($ext . DIRECTORY_SEPARATOR . $opcache)) {
34+
array_push($cmd, '-d', 'zend_extension=opcache');
35+
}
36+
array_push($cmd,
37+
'-d', 'opcache.enable_cli=1',
38+
'-d', 'opcache.file_cache="' . $cache . '"',
39+
'-d', 'opcache.file_cache_only=1',
40+
'-d', 'opcache.file_update_protection=0',
41+
...$args,
42+
);
43+
$proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
44+
echo stream_get_contents($pipes[1]);
45+
stream_get_contents($pipes[2]);
46+
proc_close($proc);
47+
}
48+
49+
function system_ids(string $cache): int {
50+
$pattern = PHP_OS_FAMILY === 'Windows' ? '/*/*' : '/*';
51+
return count(glob($cache . $pattern, GLOB_ONLYDIR));
52+
}
53+
54+
run($cache, ['-d', 'extension=dl_test', $script]);
55+
var_dump(system_ids($cache));
56+
run($cache, [$script, 'dl']);
57+
var_dump(system_ids($cache));
58+
run($cache, [$script]);
59+
var_dump(system_ids($cache));
60+
?>
61+
--CLEAN--
62+
<?php
63+
$cache = __DIR__ . DIRECTORY_SEPARATOR . 'file_cache_frameless_handler';
64+
if (is_dir($cache)) {
65+
$it = new RecursiveIteratorIterator(
66+
new RecursiveDirectoryIterator($cache, FilesystemIterator::SKIP_DOTS),
67+
RecursiveIteratorIterator::CHILD_FIRST
68+
);
69+
foreach ($it as $file) {
70+
$file->isDir() ? rmdir($file->getPathname()) : unlink($file->getPathname());
71+
}
72+
rmdir($cache);
73+
}
74+
?>
75+
--EXPECT--
76+
int(7)
77+
int(1)
78+
int(7)
79+
int(2)
80+
Error: Call to undefined function dl_test_frameless()
81+
int(2)

0 commit comments

Comments
 (0)