Skip to content

Commit 9d0c018

Browse files
committed
Make sure dummy file for fuzzing exists
1 parent 06a25c7 commit 9d0c018

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

sapi/fuzzer/fuzzer-execute-common.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fuzzer-sapi.h"
2121
#include "zend_exceptions.h"
2222

23+
#define FILE_NAME "/tmp/fuzzer.php"
2324
#define MAX_STEPS 1000
2425
#define MAX_SIZE (8 * 1024)
2526
static uint32_t steps_left;
@@ -102,12 +103,19 @@ static void fuzzer_init_php_for_execute(const char *extra_ini) {
102103
zend_compile_string = fuzzer_compile_string;
103104
}
104105

106+
ZEND_ATTRIBUTE_UNUSED static void create_file(void) {
107+
/* For opcache_invalidate() to work, the dummy file name used for fuzzing needs to
108+
* actually exist. */
109+
FILE *f = fopen(FILE_NAME, "w");
110+
fclose(f);
111+
}
112+
105113
ZEND_ATTRIBUTE_UNUSED static void opcache_invalidate(void) {
106114
steps_left = MAX_STEPS;
107115
zend_exception_save();
108116
zval retval, func, args[2];
109117
ZVAL_STRING(&func, "opcache_invalidate");
110-
ZVAL_STRING(&args[0], "/fuzzer.php");
118+
ZVAL_STRING(&args[0], FILE_NAME);
111119
ZVAL_TRUE(&args[1]);
112120
call_user_function(CG(function_table), NULL, &func, &retval, 2, args);
113121
ZEND_ASSERT(Z_TYPE(retval) == IS_TRUE);

sapi/fuzzer/fuzzer-execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
2525

2626
steps_left = MAX_STEPS;
2727
fuzzer_do_request_from_buffer(
28-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, /* before_shutdown */ NULL);
28+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, /* before_shutdown */ NULL);
2929

3030
return 0;
3131
}

sapi/fuzzer/fuzzer-function-jit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
3232
zend_alter_ini_entry_chars(
3333
jit_option, "off", sizeof("off")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
3434
fuzzer_do_request_from_buffer(
35-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
35+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
3636

3737
if (!bailed_out) {
3838
steps_left = MAX_STEPS;
3939
zend_alter_ini_entry_chars(jit_option,
4040
"function", sizeof("function")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
4141
fuzzer_do_request_from_buffer(
42-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
42+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
4343
}
4444

4545
zend_string_release(jit_option);
@@ -59,6 +59,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) {
5959
"opcache.jit_buffer_size=256M",
6060
opcache_path);
6161
free(opcache_path);
62+
63+
create_file();
6264
fuzzer_init_php_for_execute(ini_buf);
6365
return 0;
6466
}

sapi/fuzzer/fuzzer-tracing-jit.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
3232
zend_alter_ini_entry_chars(
3333
jit_option, "off", sizeof("off")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
3434
fuzzer_do_request_from_buffer(
35-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
35+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
3636

3737
if (!bailed_out) {
3838
steps_left = MAX_STEPS;
@@ -41,10 +41,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
4141
zend_execute_ex = orig_execute_ex;
4242
/* Trace & compile */
4343
fuzzer_do_request_from_buffer(
44-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, NULL);
44+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, NULL);
4545
/* Execute trace */
4646
fuzzer_do_request_from_buffer(
47-
"/fuzzer.php", (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
47+
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
4848
zend_execute_ex = fuzzer_execute_ex;
4949
}
5050

@@ -70,6 +70,8 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) {
7070
"opcache.jit_max_root_traces=32768",
7171
opcache_path);
7272
free(opcache_path);
73+
74+
create_file();
7375
fuzzer_init_php_for_execute(ini_buf);
7476
return 0;
7577
}

0 commit comments

Comments
 (0)