aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/spidermonkey-ufi/target.c
blob: 3538d29c9a00aa858f1bbc932ff5d39cfa1fcb1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define STRINGLIT(S) #S
#define STRINGIFY(S) STRINGLIT(S)

// Required for oss-fuzz to consider the binary a target.
static const char* magic __attribute__((used)) = "LLVMFuzzerTestOneInput";

int main(int argc, char* argv[]) {
  setenv("HOME", "/tmp", 0);
  setenv("LIBFUZZER", "1", 1);
  setenv("FUZZER", STRINGIFY(FUZZ_TARGET), 1);

  char* options = getenv("ASAN_OPTIONS");
  if (options) {
    char* ptr;
    char* new_options = strdup(options);

    // https://bugzilla.mozilla.org/1477846
    ptr = strstr(new_options, "detect_stack_use_after_return=1");
    if (ptr) ptr[30] = '0';

    // https://bugzilla.mozilla.org/1477844
    ptr = strstr(new_options, "detect_leaks=1");
    if (ptr) ptr[13] = '0';

    setenv("ASAN_OPTIONS", new_options, 1);
    free(new_options);
  }

  int ret = execv("./fuzz-tests", argv);
  if (ret)
    perror("execv");
  return ret;
}