Coverage Report

Created: 2026-06-02 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/sapi/fuzzer/fuzzer-tracing-jit.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Authors: Nikita Popov <nikic@php.net>                                |
12
   +----------------------------------------------------------------------+
13
 */
14
15
#include "fuzzer-execute-common.h"
16
17
18.0k
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
18
18.0k
  if (Size > MAX_SIZE) {
19
    /* Large inputs have a large impact on fuzzer performance,
20
     * but are unlikely to be necessary to reach new codepaths. */
21
1
    return 0;
22
1
  }
23
24
18.0k
  zend_string *jit_option = ZSTR_INIT_LITERAL("opcache.jit", 1);
25
26
  /* First run without JIT to determine whether we bail out. We should not run JITed code if
27
   * we bail out here, as the JIT code may loop infinitely. */
28
18.0k
  steps_left = MAX_STEPS;
29
18.0k
  bailed_out = false;
30
18.0k
  zend_alter_ini_entry_chars(
31
18.0k
    jit_option, "off", sizeof("off")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
32
18.0k
  fuzzer_do_request_from_buffer(
33
18.0k
    FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
34
35
18.0k
  if (!bailed_out) {
36
13.1k
    steps_left = MAX_STEPS;
37
13.1k
    zend_alter_ini_entry_chars(jit_option,
38
13.1k
      "tracing", sizeof("tracing")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
39
13.1k
    zend_execute_ex = orig_execute_ex;
40
    /* Trace & compile */
41
13.1k
    fuzzer_do_request_from_buffer(
42
13.1k
      FILE_NAME, (const char *) Data, Size, /* execute */ 1, NULL);
43
    /* Execute trace */
44
13.1k
    fuzzer_do_request_from_buffer(
45
13.1k
      FILE_NAME, (const char *) Data, Size, /* execute */ 1, opcache_invalidate);
46
13.1k
    zend_execute_ex = fuzzer_execute_ex;
47
13.1k
  }
48
49
18.0k
  zend_string_release(jit_option);
50
51
18.0k
  return 0;
52
18.0k
}
53
54
2
int LLVMFuzzerInitialize(int *argc, char ***argv) {
55
2
  char ini_buf[512];
56
2
  snprintf(ini_buf, sizeof(ini_buf),
57
2
    "opcache.validate_timestamps=0\n"
58
2
    "opcache.file_update_protection=0\n"
59
2
    "opcache.memory_consumption=1024\n"
60
2
    "opcache.jit_buffer_size=128M\n"
61
2
    "opcache.jit_hot_func=1\n"
62
2
    "opcache.jit_hot_loop=1\n"
63
2
    "opcache.jit_hot_return=1\n"
64
2
    "opcache.jit_hot_side_exit=1\n"
65
2
    "opcache.jit_max_root_traces=100000\n"
66
2
    "opcache.jit_max_side_traces=100000\n"
67
2
    "opcache.jit_max_exit_counters=100000\n"
68
2
    "opcache.protect_memory=1\n");
69
70
2
  create_file();
71
2
  fuzzer_init_php_for_execute(ini_buf);
72
2
  return 0;
73
2
}