mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Add basic structure for fuzzing targets
General changes: * Add -D/--deterministic command line option as convenience/alternative to -G/--load-seeds (i.e. no file needed, it just uses zero-initialized random seeds). It also changes Broker data stores over to using deterministic timing rather than real time. * Add option to make Reporter abort on runtime scripting errors
This commit is contained in:
parent
f849571910
commit
8f1b34b915
20 changed files with 1290 additions and 928 deletions
56
src/fuzzers/FuzzBuffer.cc
Normal file
56
src/fuzzers/FuzzBuffer.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
#if !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "FuzzBuffer.h"
|
||||
|
||||
bool zeek::FuzzBuffer::Valid() const
|
||||
{
|
||||
if ( end - begin < PKT_MAGIC_LEN + 2 )
|
||||
return false;
|
||||
|
||||
if ( memcmp(begin, PKT_MAGIC, PKT_MAGIC_LEN) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int zeek::FuzzBuffer::Next(const unsigned char** chunk, size_t* len, bool* is_orig)
|
||||
{
|
||||
if ( begin == end )
|
||||
{
|
||||
*chunk = nullptr;
|
||||
*len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto pos = (const unsigned char*)memmem(begin, end - begin,
|
||||
PKT_MAGIC, PKT_MAGIC_LEN);
|
||||
|
||||
if ( ! pos )
|
||||
return -1;
|
||||
|
||||
begin += PKT_MAGIC_LEN;
|
||||
auto remaining = end - begin;
|
||||
|
||||
if ( remaining < 2 )
|
||||
return -2;
|
||||
|
||||
*is_orig = begin[0] & 0x01;
|
||||
begin += 1;
|
||||
|
||||
*chunk = begin;
|
||||
|
||||
auto next = (const unsigned char*)memmem(begin, end - begin,
|
||||
PKT_MAGIC, PKT_MAGIC_LEN);
|
||||
|
||||
if ( next )
|
||||
begin = next;
|
||||
else
|
||||
begin = end;
|
||||
|
||||
*len = begin - *chunk;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue