From bc2d02e3a9c080dcc6a61f37ae25dec634a994db Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 30 Jul 2025 09:01:10 +0200 Subject: [PATCH] Fix fuzzer after opcache became mandatory (#19292) --- sapi/fuzzer/fuzzer-execute-common.h | 30 ----------------------------- sapi/fuzzer/fuzzer-function-jit.c | 8 +------- sapi/fuzzer/fuzzer-tracing-jit.c | 8 +------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/sapi/fuzzer/fuzzer-execute-common.h b/sapi/fuzzer/fuzzer-execute-common.h index 081ab4d30e8..b3a77268b39 100644 --- a/sapi/fuzzer/fuzzer-execute-common.h +++ b/sapi/fuzzer/fuzzer-execute-common.h @@ -139,33 +139,3 @@ ZEND_ATTRIBUTE_UNUSED static void opcache_invalidate(void) { zval_ptr_dtor(&retval); 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); -} diff --git a/sapi/fuzzer/fuzzer-function-jit.c b/sapi/fuzzer/fuzzer-function-jit.c index 92415c2a0e1..d2117f0027c 100644 --- a/sapi/fuzzer/fuzzer-function-jit.c +++ b/sapi/fuzzer/fuzzer-function-jit.c @@ -50,18 +50,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } int LLVMFuzzerInitialize(int *argc, char ***argv) { - char *opcache_path = get_opcache_path(); - assert(opcache_path && "Failed to determine opcache path"); - char ini_buf[512]; snprintf(ini_buf, sizeof(ini_buf), - "zend_extension=%s\n" "opcache.validate_timestamps=0\n" "opcache.file_update_protection=0\n" "opcache.jit_buffer_size=128M\n" - "opcache.protect_memory=1\n", - opcache_path); - free(opcache_path); + "opcache.protect_memory=1\n"); create_file(); fuzzer_init_php_for_execute(ini_buf); diff --git a/sapi/fuzzer/fuzzer-tracing-jit.c b/sapi/fuzzer/fuzzer-tracing-jit.c index 437938d0902..65d661f139c 100644 --- a/sapi/fuzzer/fuzzer-tracing-jit.c +++ b/sapi/fuzzer/fuzzer-tracing-jit.c @@ -54,12 +54,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } int LLVMFuzzerInitialize(int *argc, char ***argv) { - char *opcache_path = get_opcache_path(); - assert(opcache_path && "Failed to determine opcache path"); - char ini_buf[512]; snprintf(ini_buf, sizeof(ini_buf), - "zend_extension=%s\n" "opcache.validate_timestamps=0\n" "opcache.file_update_protection=0\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_side_traces=100000\n" "opcache.jit_max_exit_counters=100000\n" - "opcache.protect_memory=1\n", - opcache_path); - free(opcache_path); + "opcache.protect_memory=1\n"); create_file(); fuzzer_init_php_for_execute(ini_buf);