]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: JSON parser fuzzer
authorJouni Malinen <j@w1.fi>
Sat, 9 Feb 2019 19:38:56 +0000 (21:38 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 11 Feb 2019 00:35:29 +0000 (02:35 +0200)
test-json can be used for fuzz testing the JSON parser implementation in
src/utils/json.c.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/Makefile
tests/Makefile
tests/test-json.c [new file with mode: 0644]

index 52efc5321fca1de538cf75562f8f3afc53aae04e..1ee2bee67f6b34c889d0d78bc36f1c6a27a9ca46 100644 (file)
@@ -19,6 +19,7 @@ LIB_OBJS= \
        common.o \
        crc32.o \
        ip_addr.o \
+       json.o \
        radiotap.o \
        trace.o \
        uuid.o \
index 93a844b473fac4fa88cbe8efd94527a0491bd181..fc449b8ec2b297a2c91027b8045db37afe12cb3f 100644 (file)
@@ -61,6 +61,9 @@ test-https: test-https.o $(LIBS)
 test-https_server: test-https_server.o $(LIBS)
        $(LDO) $(LDFLAGS) -o $@ $< $(LLIBS)
 
+test-json: test-json.o $(LIBS)
+       $(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
+
 test-list: test-list.o $(LIBS)
        $(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
 
@@ -107,6 +110,7 @@ clean:
        $(MAKE) -C ../src clean
        rm -f $(TESTS) *~ *.o *.d
        rm -f test-https
+       rm -f test-json
        rm -f test-tls
        rm -f test_x509v3_nist.out.*
        rm -f test_x509v3_nist2.out.*
diff --git a/tests/test-json.c b/tests/test-json.c
new file mode 100644 (file)
index 0000000..c7cb460
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * JSON parser - test program
+ * Copyright (c) 2019, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+#include "utils/os.h"
+#include "utils/json.h"
+
+
+int main(int argc, char *argv[])
+{
+       char *buf;
+       size_t len;
+       struct json_token *root;
+
+       if (argc < 2)
+               return -1;
+
+       buf = os_readfile(argv[1], &len);
+       if (!buf)
+               return -1;
+
+       root = json_parse(buf, len);
+       os_free(buf);
+       if (root) {
+               size_t buflen = 10000;
+
+               buf = os_zalloc(buflen);
+               if (buf) {
+                       json_print_tree(root, buf, buflen);
+                       printf("%s\n", buf);
+                       os_free(buf);
+               }
+               json_free(root);
+       } else {
+               printf("JSON parsing failed\n");
+       }
+
+       return 0;
+}