Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sapi/fuzzer/fuzzer-execute-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@ ZEND_ATTRIBUTE_UNUSED static void opcache_invalidate(void) {
zval_ptr_dtor(&retval);
EG(exception) = exception;
}

ZEND_ATTRIBUTE_UNUSED static void set_jit_option(zend_string *jit_option, const char *value) {
if (zend_alter_ini_entry_chars(
jit_option, value, strlen(value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == FAILURE) {
/* Fail loudly instead of silently fuzzing without the JIT. */
fprintf(stderr, "Failed to set opcache.jit=%s\n", value);
abort();
}
}
8 changes: 4 additions & 4 deletions sapi/fuzzer/fuzzer-function-jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
* we bail out here, as the JIT code may loop infinitely. */
steps_left = MAX_STEPS;
bailed_out = false;
zend_alter_ini_entry_chars(
jit_option, "off", sizeof("off")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
set_jit_option(jit_option, "off");
fuzzer_do_request_from_buffer(
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);

if (!bailed_out) {
steps_left = MAX_STEPS;
zend_alter_ini_entry_chars(jit_option,
"function", sizeof("function")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
set_jit_option(jit_option, "function");
zend_execute_ex = orig_execute_ex;
fuzzer_do_request_from_buffer(
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
Expand All @@ -50,6 +48,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
int LLVMFuzzerInitialize(int *argc, char ***argv) {
char ini_buf[512];
snprintf(ini_buf, sizeof(ini_buf),
/* The default opcache.jit=disable does not allow enabling the JIT at runtime. */
"opcache.jit=off\n"
"opcache.validate_timestamps=0\n"
"opcache.file_update_protection=0\n"
"opcache.jit_buffer_size=128M\n"
Expand Down
8 changes: 4 additions & 4 deletions sapi/fuzzer/fuzzer-tracing-jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
* we bail out here, as the JIT code may loop infinitely. */
steps_left = MAX_STEPS;
bailed_out = false;
zend_alter_ini_entry_chars(
jit_option, "off", sizeof("off")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
set_jit_option(jit_option, "off");
fuzzer_do_request_from_buffer(
FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);

if (!bailed_out) {
steps_left = MAX_STEPS;
zend_alter_ini_entry_chars(jit_option,
"tracing", sizeof("tracing")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
set_jit_option(jit_option, "tracing");
zend_execute_ex = orig_execute_ex;
/* Trace & compile */
fuzzer_do_request_from_buffer(
Expand All @@ -54,6 +52,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
int LLVMFuzzerInitialize(int *argc, char ***argv) {
char ini_buf[512];
snprintf(ini_buf, sizeof(ini_buf),
/* The default opcache.jit=disable does not allow enabling the JIT at runtime. */
"opcache.jit=off\n"
"opcache.validate_timestamps=0\n"
"opcache.file_update_protection=0\n"
"opcache.memory_consumption=1024\n"
Expand Down
Loading