Skip to content

Commit 4821d98

Browse files
Merge pull request #105 from Easton97-Jens/codex/fix-afl++-fuzzing-harness-input-handling-562xti
Fix AFL++ fuzzer input handling and null operator safety
2 parents 094c698 + bebecb7 commit 4821d98

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

test/fuzzer/afl_fuzzer.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,15 @@ using namespace modsecurity;
122122
#include <signal.h>
123123
#include <string.h>
124124

125+
#ifndef __AFL_LOOP
126+
#define __AFL_LOOP(x) (1)
127+
#endif
128+
125129
inline void op_test(const std::string &opName, const std::string &s) {
126130
Operator *op = Operator::instantiate(opName, "");
131+
if (op == nullptr) {
132+
return;
133+
}
127134
op->init("", nullptr);
128135
op->evaluate(nullptr, nullptr, s, nullptr);
129136
delete op;
@@ -142,7 +149,12 @@ int main(int argc, char** argv) {
142149
memset(buf, 0, 128);
143150
read_bytes = read(STDIN_FILENO, buf, 128);
144151

145-
std::string currentString = std::string(read_bytes, 128);
152+
if (read_bytes <= 0) {
153+
continue;
154+
}
155+
156+
std::string currentString =
157+
std::string(reinterpret_cast<const char *>(buf), read_bytes);
146158
const std::string& s = currentString;
147159
#if 0
148160
std::string z = lastString;

0 commit comments

Comments
 (0)