#define _GNU_SOURCE #include #include #include /* gcc -shared -fPIC exit-on-EOF.c -o exit-on-EOF.so -ldl */ /* LD_PRELOAD=./exit-on-EOF.so ./test */ /* AFL_PRELOAD=./exit-on-EOF.so afl-fuzz -i in -o out -n -- ./test */ typedef int (*orig_read_f_type)(int fd, void *buf, int count); int read(int fd, void *buf, int count) { orig_read_f_type orig_read = (orig_read_f_type)dlsym(RTLD_NEXT, "read"); for (int i = 0; i < count; ++i) { int n = orig_read(fd, buf++, 1); if (n == 0) { printf("EOF!\n"); exit(-1337); } } return count; }