Skip to content

Commit

Permalink
tighten memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed Apr 27, 2019
1 parent e2301f2 commit 793d97b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions fuzzing/one_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ doit(const uint8_t* Data, std::size_t Size)
Data += N;
Size -= N;
// allocates as tight as possible, making it easier to catch buffer overruns
std::vector<char> buf(Data, Data + Size);
buf.resize(Size + 1, '\0');
// also, make it null terminated.
std::vector<char> buf(Size + 1);
std::memcpy(buf.data(), Data, Size);
std::string message = fmt::format(buf.data(), item);
}

Expand Down
9 changes: 4 additions & 5 deletions fuzzing/two_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ doit_time(const uint8_t* Data, std::size_t Size)
std::memcpy(&item, Data, N);
Data += N;
Size -= N;
// allocates as tight as possible, making it easier to catch buffer overruns
std::vector<char> buf(Data, Data + Size);
buf.resize(Size + 1, '\0');
// allocates as tight as possible, making it easier to catch buffer overruns.
// also, make it null terminated.
std::vector<char> buf(Size + 1);
std::memcpy(buf.data(), Data, Size);
auto* b = std::localtime(&item);
if (b) {
std::string message = fmt::format(buf.data(), *b);
Expand Down Expand Up @@ -113,8 +114,6 @@ LLVMFuzzerTestOneInput(const uint8_t* Data, std::size_t Size)

auto outer = [=](auto param1) {
auto inner = [=](auto param2) {
// std::cout<<"invoked with param1="<<sizeof(param1)<<"
// param2="<<sizeof(param2)<<'\n';
doit<decltype(param1), decltype(param2)>(Data, Size);
};
invoke(second, inner);
Expand Down

0 comments on commit 793d97b

Please sign in to comment.