File: test-dlopen.c

package info (click to toggle)
aflplusplus 4.21c-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,496 kB
  • sloc: ansic: 110,361; cpp: 16,725; sh: 4,855; python: 3,793; makefile: 963; javascript: 515; java: 43; sql: 3; xml: 1
file content (39 lines) | stat: -rw-r--r-- 755 bytes parent folder | download
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 <errno.h>
#include <dlfcn.h>
#include <stdlib.h>

int main(int argc, char **argv) {

  if (!getenv("TEST_DLOPEN_TARGET")) {

    fprintf(stderr, "Error: TEST_DLOPEN_TARGET not set!\n");
    return 1;

  }

  void *lib = dlopen(getenv("TEST_DLOPEN_TARGET"), RTLD_LAZY);
  if (!lib) {

    perror(dlerror());
    return 2;

  }

  int (*func)(int, char **) = dlsym(lib, "main_exported");
  if (!func) {

    fprintf(stderr, "Error: main_exported not found!\n");
    return 3;

  }

  // must use deferred forkserver as otherwise AFL++ instrumentation aborts
  // because all dlopen() of instrumented libs must be before the forkserver
  __AFL_INIT();

  fprintf(stderr, "Running main_exported\n");
  return func(argc, argv);

}