blob: 595da62f223c5259d01abfdd8333c1418b613bb2 [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
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +02008LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, const char *data, struct lys_module *mod);
9
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010010int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len)
11{
12 struct lys_module *mod = NULL;
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020013 struct lys_yang_parser_ctx *context = NULL;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010014 uint8_t *data = NULL;
15 struct ly_ctx *ctx = NULL;
16 static bool log = false;
17 LY_ERR err;
18
19 if (!log) {
20 ly_log_options(0);
21 log = true;
22 }
23
24 err = ly_ctx_new(NULL, 0, &ctx);
25 if (err != LY_SUCCESS) {
26 fprintf(stderr, "Failed to create new context\n");
27 return 0;
28 }
29
30 data = malloc(len + 1);
31 if (data == NULL) {
32 fprintf(stderr, "Out of memory\n");
33 return 0;
34 }
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010035 memcpy(data, buf, len);
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020036 data[len] = 0;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010037
38 mod = calloc(1, sizeof *mod);
39 if (mod == NULL) {
40 fprintf(stderr, "Out of memory\n");
41 return 0;
42 }
43 mod->ctx = ctx;
44
45 yang_parse_module(&context, data, mod);
46
47 free(data);
48 free(mod);
49 ly_ctx_destroy(ctx, NULL);
50 return 0;
51}