blob: 4b464a7312ea880fb9514603b9976fd829dd836a [file] [log] [blame]
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <stdbool.h>
4
Radek Krejcie5875092020-05-13 20:42:15 +02005#include "../../src/common.h"
6#include "../../src/tree_schema_internal.h"
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01007
8int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len)
9{
10 struct lys_module *mod = NULL;
11 struct lys_parser_ctx *context = NULL;
12 uint8_t *data = NULL;
13 struct ly_ctx *ctx = NULL;
14 static bool log = false;
15 LY_ERR err;
16
17 if (!log) {
18 ly_log_options(0);
19 log = true;
20 }
21
22 err = ly_ctx_new(NULL, 0, &ctx);
23 if (err != LY_SUCCESS) {
24 fprintf(stderr, "Failed to create new context\n");
25 return 0;
26 }
27
28 data = malloc(len + 1);
29 if (data == NULL) {
30 fprintf(stderr, "Out of memory\n");
31 return 0;
32 }
33 data[len] = 0;
34 memcpy(data, buf, len);
35
36 mod = calloc(1, sizeof *mod);
37 if (mod == NULL) {
38 fprintf(stderr, "Out of memory\n");
39 return 0;
40 }
41 mod->ctx = ctx;
42
43 yang_parse_module(&context, data, mod);
44
45 free(data);
46 free(mod);
47 ly_ctx_destroy(ctx, NULL);
48 return 0;
49}