File: fuzzer.c

package info (click to toggle)
yyjson 0.12.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,484 kB
  • sloc: ansic: 28,930; xml: 253; javascript: 99; sh: 13; cpp: 8; makefile: 8; objc: 7
file content (26 lines) | stat: -rw-r--r-- 984 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <yyjson.h>

static void test_with_flags(const uint8_t *data, size_t size,
                            yyjson_read_flag rflg, yyjson_write_flag wflg) {
    yyjson_doc *idoc = yyjson_read((const char *)data, size, rflg);
    yyjson_mut_doc *mdoc = yyjson_doc_mut_copy(idoc, NULL);
    char *ijson = yyjson_write(idoc, wflg, NULL);
    if (ijson) free((void *)ijson);
    char *mjson = yyjson_mut_write(mdoc, wflg, NULL);
    if (mjson) free((void *)mjson);
    yyjson_doc_free(idoc);
    yyjson_mut_doc_free(mdoc);
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    test_with_flags(data, size,
                    YYJSON_READ_NOFLAG,
                    YYJSON_WRITE_NOFLAG);
    test_with_flags(data, size,
                    YYJSON_READ_JSON5,
                    YYJSON_WRITE_PRETTY |
                    YYJSON_WRITE_ESCAPE_UNICODE |
                    YYJSON_WRITE_ESCAPE_SLASHES |
                    YYJSON_WRITE_ALLOW_INF_AND_NAN);
    return 0;
}