Fuzzer for various hex-related utility functions

This commit is contained in:
dmiller 2026-08-21 01:14:27 +00:00
parent 23d13f12f7
commit 3ca969ce85
2 changed files with 33 additions and 0 deletions

2
fuzz/.gitignore vendored
View file

@ -3,4 +3,6 @@ fuzz_dns_packet_parseFromBuffer
fuzz_ippackethdrinfo
fuzz_traceroute_decode_reply
fuzz_gettcpopt_ts
fuzz_validatepkt
fuzz_hexutils
corpus/

31
fuzz/fuzz_hexutils.cc Normal file
View file

@ -0,0 +1,31 @@
#include "common.h"
#include "../output.h"
#include "../utils.h"
#include <stddef.h>
#include <stdint.h>
extern "C"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
fuzz_init();
unsigned int newlen = 0;
char *cbuf = new char[size + 1];
memcpy(cbuf, data, size);
cbuf[size] = '\0';
char *cdata = cstring_unescape(cbuf, &newlen);
int bufsize = newlen * 4 + newlen / 8 + 1;
char *buf = new char[bufsize];
bintohexstr(buf, bufsize, cdata, (int)newlen);
size_t phs_len = 0;
u8 *phs_buf = parse_hex_string(buf, &phs_len);
if (phs_buf != NULL) {
volatile std::string safe = protect_xml(std::string((char *)phs_buf, phs_len));
(void) safe;
}
delete[] buf;
delete[] cbuf;
return 0;
}