[PATCH] D28718: [libFuzzer] Avoid undefined behavior. Properly discard output to stdout and stderr.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 20:49:42 PST 2017


mpividori added a comment.

For example, before this commit, if you compile this simple test function with `libFuzzer` and execute:   `./my_fuzzer -close_fd_mask=1`  , it will write to the `testout` file many times the message that was expected to be send to stdout.

  #include <cstdint>
  #include <fcntl.h>
  #include <iostream>
  #include <unistd.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  
  static volatile int Sink;
  
  extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    int fd = open("testout", O_CREAT | O_WRONLY | O_APPEND);
    if (fd == -1) return 1;
    std::cout << "SOME MSG TO STDOUT, NOT TO THE FILE" << std::endl;
    close(fd);
    return 0;
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D28718





More information about the llvm-commits mailing list