mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-13 02:28:09 +00:00
Fix memory leak in libprotobuf-mutator-example
This commit is contained in:
@ -99,10 +99,12 @@ extern "C" size_t afl_custom_fuzz(MyMutator *mutator, // return value from afl_c
|
|||||||
std::string s = ProtoToData(*p);
|
std::string s = ProtoToData(*p);
|
||||||
// Copy to a new buffer ( mutated_out )
|
// Copy to a new buffer ( mutated_out )
|
||||||
size_t mutated_size = s.size() <= max_size ? s.size() : max_size; // check if raw data's size is larger than max_size
|
size_t mutated_size = s.size() <= max_size ? s.size() : max_size; // check if raw data's size is larger than max_size
|
||||||
uint8_t *mutated_out = new uint8_t[mutated_size+1];
|
|
||||||
memcpy(mutated_out, s.c_str(), mutated_size); // copy the mutated data
|
delete mutator->mutated_out;
|
||||||
|
mutator->mutated_out = new uint8_t[mutated_size+1];
|
||||||
|
memcpy(mutator->mutated_out, s.c_str(), mutated_size); // copy the mutated data
|
||||||
// Assign the mutated data and return mutated_size
|
// Assign the mutated data and return mutated_size
|
||||||
*out_buf = mutated_out;
|
*out_buf = mutator->mutated_out;
|
||||||
return mutated_size;
|
return mutated_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,4 +2,6 @@
|
|||||||
#include "test.pb.h"
|
#include "test.pb.h"
|
||||||
|
|
||||||
class MyMutator : public protobuf_mutator::Mutator {
|
class MyMutator : public protobuf_mutator::Mutator {
|
||||||
|
public:
|
||||||
|
uint8_t *mutated_out = nullptr;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user