summaryrefslogtreecommitdiffstats
path: root/tests/fuzz/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-23 09:41:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-23 11:00:43 +0000
commitd0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af (patch)
tree7ea7c5e622a5d7c9c989057a1eca8954c4d7fefb /tests/fuzz/main.c
parentInitial commit. (diff)
downloadlibyang3-d0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af.tar.xz
libyang3-d0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af.zip
Adding upstream version 3.1.0+dfsg.upstream/3.1.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fuzz/main.c')
-rw-r--r--tests/fuzz/main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/fuzz/main.c b/tests/fuzz/main.c
new file mode 100644
index 0000000..a4b64b5
--- /dev/null
+++ b/tests/fuzz/main.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len);
+
+#ifdef __AFL_COMPILER
+
+int main(void) {
+ int ret;
+ uint8_t buf[64 * 1024];
+
+#ifdef __AFL_LOOP
+ while (__AFL_LOOP(10000))
+#endif
+ {
+ ret = fread(buf, 1, sizeof(buf), stdin);
+ if (ret < 0) {
+ return 0;
+ }
+
+ LLVMFuzzerTestOneInput(buf, ret);
+
+ }
+
+ return 0;
+}
+
+#else
+
+int
+main(void)
+{
+ int ret;
+ uint8_t buf[64 * 1024];
+
+ ret = fread(buf, 1, sizeof(buf), stdin);
+ if (ret < 0) {
+ return 0;
+ }
+
+ LLVMFuzzerTestOneInput(buf, ret);
+
+ return 0;
+}
+
+#endif /* __AFL_COMPILER */