-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnofuzz.cc
55 lines (45 loc) · 1.27 KB
/
nofuzz.cc
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
namespace {
using uint8 = unsigned char;
using uint = unsigned int;
using uintmax = std::uintmax_t;
using intmax = std::intmax_t;
// Shorthand for static_cast.
template<typename X, typename Y>
[[nodiscard]] constexpr X
sc(Y v) { return static_cast<X>(v); }
} // namespace
extern "C" int
LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
int
main(int argc, char *argv[]) {
std::ios::sync_with_stdio(false);
for (int i{1}; i < argc; i++) {
std::filesystem::path f(argv[i]);
if (!std::filesystem::exists(f)) {
std::cerr << "nofuzz: " << f << " does not exist\n\n";
continue;
}
if (!std::filesystem::is_regular_file(f)) {
std::cerr << "nofuzz: " << f << " is not a regular file\n\n";
continue;
}
auto sz{std::filesystem::file_size(f)};
if (sc<intmax>(sz) < 0) {
std::cerr << "nofuzz: unexpected error with " << f << "\n\n";
continue;
}
std::cerr << f << ":\n";
std::vector<unsigned char> buffer;
buffer.resize(sc<decltype(buffer)::size_type>(sz));
auto a{buffer.data()};
std::ifstream(f, std::ios_base::binary).read(reinterpret_cast<char*>(a), sc<intmax>(sz));
LLVMFuzzerTestOneInput(a, sz);
std::cerr << '\n';
}
return 0;
}