summaryrefslogtreecommitdiffstats
path: root/src/c-ares/test/ares-test-fuzz.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/c-ares/test/ares-test-fuzz.c
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/c-ares/test/ares-test-fuzz.c')
-rw-r--r--src/c-ares/test/ares-test-fuzz.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/c-ares/test/ares-test-fuzz.c b/src/c-ares/test/ares-test-fuzz.c
new file mode 100644
index 000000000..2b5c16151
--- /dev/null
+++ b/src/c-ares/test/ares-test-fuzz.c
@@ -0,0 +1,46 @@
+#include <stddef.h>
+
+#include "ares.h"
+
+// Entrypoint for Clang's libfuzzer
+int LLVMFuzzerTestOneInput(const unsigned char *data,
+ unsigned long size) {
+ // Feed the data into each of the ares_parse_*_reply functions.
+ struct hostent *host = NULL;
+ struct ares_addrttl info[5];
+ int count = 5;
+ ares_parse_a_reply(data, size, &host, info, &count);
+ if (host) ares_free_hostent(host);
+
+ host = NULL;
+ struct ares_addr6ttl info6[5];
+ count = 5;
+ ares_parse_aaaa_reply(data, size, &host, info6, &count);
+ if (host) ares_free_hostent(host);
+
+ host = NULL;
+ unsigned char addrv4[4] = {0x10, 0x20, 0x30, 0x40};
+ ares_parse_ptr_reply(data, size, addrv4, sizeof(addrv4), AF_INET, &host);
+ if (host) ares_free_hostent(host);
+
+ host = NULL;
+ ares_parse_ns_reply(data, size, &host);
+ if (host) ares_free_hostent(host);
+
+ struct ares_srv_reply* srv = NULL;
+ ares_parse_srv_reply(data, size, &srv);
+ if (srv) ares_free_data(srv);
+
+ struct ares_mx_reply* mx = NULL;
+ ares_parse_mx_reply(data, size, &mx);
+ if (mx) ares_free_data(mx);
+
+ struct ares_txt_reply* txt = NULL;
+ ares_parse_txt_reply(data, size, &txt);
+ if (txt) ares_free_data(txt);
+
+ struct ares_soa_reply* soa = NULL;
+ ares_parse_soa_reply(data, size, &soa);
+ if (soa) ares_free_data(soa);
+ return 0;
+}