Fix fuzzer after opcache became mandatory (#19292)

This commit is contained in:
Niels Dossche 2025-07-30 09:01:10 +02:00 committed by GitHub
parent c1b129bd18
commit bc2d02e3a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 44 deletions

View file

@ -139,33 +139,3 @@ ZEND_ATTRIBUTE_UNUSED static void opcache_invalidate(void) {
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
zend_exception_restore(); zend_exception_restore();
} }
ZEND_ATTRIBUTE_UNUSED char *get_opcache_path(void) {
/* Try relative to cwd. */
char *p = realpath("modules/opcache.so", NULL);
if (p) {
return p;
}
/* Try relative to binary location. */
char path[MAXPATHLEN];
#if defined(__FreeBSD__)
size_t pathlen = sizeof(path);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
if (sysctl(mib, 4, path, &pathlen, NULL, 0) < 0) {
#else
if (readlink("/proc/self/exe", path, sizeof(path)) < 0) {
#endif
ZEND_ASSERT(0 && "Failed to get binary path");
return NULL;
}
/* Get basename. */
char *last_sep = strrchr(path, '/');
if (last_sep) {
*last_sep = '\0';
}
strlcat(path, "/modules/opcache.so", sizeof(path));
return realpath(path, NULL);
}

View file

@ -50,18 +50,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
} }
int LLVMFuzzerInitialize(int *argc, char ***argv) { int LLVMFuzzerInitialize(int *argc, char ***argv) {
char *opcache_path = get_opcache_path();
assert(opcache_path && "Failed to determine opcache path");
char ini_buf[512]; char ini_buf[512];
snprintf(ini_buf, sizeof(ini_buf), snprintf(ini_buf, sizeof(ini_buf),
"zend_extension=%s\n"
"opcache.validate_timestamps=0\n" "opcache.validate_timestamps=0\n"
"opcache.file_update_protection=0\n" "opcache.file_update_protection=0\n"
"opcache.jit_buffer_size=128M\n" "opcache.jit_buffer_size=128M\n"
"opcache.protect_memory=1\n", "opcache.protect_memory=1\n");
opcache_path);
free(opcache_path);
create_file(); create_file();
fuzzer_init_php_for_execute(ini_buf); fuzzer_init_php_for_execute(ini_buf);

View file

@ -54,12 +54,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
} }
int LLVMFuzzerInitialize(int *argc, char ***argv) { int LLVMFuzzerInitialize(int *argc, char ***argv) {
char *opcache_path = get_opcache_path();
assert(opcache_path && "Failed to determine opcache path");
char ini_buf[512]; char ini_buf[512];
snprintf(ini_buf, sizeof(ini_buf), snprintf(ini_buf, sizeof(ini_buf),
"zend_extension=%s\n"
"opcache.validate_timestamps=0\n" "opcache.validate_timestamps=0\n"
"opcache.file_update_protection=0\n" "opcache.file_update_protection=0\n"
"opcache.memory_consumption=1024\n" "opcache.memory_consumption=1024\n"
@ -71,9 +67,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) {
"opcache.jit_max_root_traces=100000\n" "opcache.jit_max_root_traces=100000\n"
"opcache.jit_max_side_traces=100000\n" "opcache.jit_max_side_traces=100000\n"
"opcache.jit_max_exit_counters=100000\n" "opcache.jit_max_exit_counters=100000\n"
"opcache.protect_memory=1\n", "opcache.protect_memory=1\n");
opcache_path);
free(opcache_path);
create_file(); create_file();
fuzzer_init_php_for_execute(ini_buf); fuzzer_init_php_for_execute(ini_buf);