-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Expand file tree
/
Copy pathstatic_cache_hook_safety.phpt
More file actions
50 lines (43 loc) · 1.35 KB
/
Copy pathstatic_cache_hook_safety.phpt
File metadata and controls
50 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--TEST--
OPcache static cache init hooks are request guarded
--SKIPIF--
<?php
$zendDir = dirname(__DIR__);
foreach (['zend_object_handlers.c', 'zend_vm_def.h', 'zend_vm_execute.h'] as $file) {
if (!is_file($zendDir . '/' . $file)) {
die('skip source tree required');
}
}
?>
--FILE--
<?php
function requireGuardedHook(string $source, string $file, string $hook, int $minimum): void
{
$unguarded = 'UNEXPECTED(' . $hook . ' != NULL)';
if (str_contains($source, $unguarded)) {
throw new RuntimeException($file . ' calls ' . $hook . ' without the request guard');
}
$pattern = '/EG\\(static_cache_class_access_active\\) &&\\s+' . preg_quote($hook, '/') . ' != NULL\\)\\s*\\)?\\s*\\{\\s+' . preg_quote($hook, '/') . '\\(/s';
if (preg_match_all($pattern, $source) < $minimum) {
throw new RuntimeException($file . ' is missing the guarded ' . $hook . ' calls');
}
}
$zendDir = dirname(__DIR__);
requireGuardedHook(
file_get_contents($zendDir . '/zend_object_handlers.c'),
'zend_object_handlers.c',
'zend_class_init_statics_hook',
1
);
foreach (['zend_vm_def.h' => 2, 'zend_vm_execute.h' => 4] as $file => $minimum) {
requireGuardedHook(
file_get_contents($zendDir . '/' . $file),
$file,
'zend_function_init_statics_hook',
$minimum
);
}
echo "OK\n";
?>
--EXPECT--
OK