blob: 59884f3ace371998b04fcb15806caecc3f7ad5e3 [file] [log] [blame]
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <stdbool.h>
4
5#include "libyang.h"
6
7int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len)
8{
9 struct ly_ctx *ctx = NULL;
10 static bool log = false;
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020011 char *data = NULL;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010012 LY_ERR err;
13
14 if (!log) {
15 ly_log_options(0);
16 log = true;
17 }
18
19 err = ly_ctx_new(NULL, 0, &ctx);
20 if (err != LY_SUCCESS) {
21 fprintf(stderr, "Failed to create context\n");
22 exit(EXIT_FAILURE);
23 }
24
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020025 data = malloc(len + 1);
26 if (data == NULL) {
27 return 0;
28 }
29
30 memcpy(data, buf, len);
31 data[len] = 0;
32
Luka Koznjaka7ade842020-09-14 13:56:03 +020033 lys_parse_mem(ctx, data, LYS_IN_YANG, NULL);
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010034 ly_ctx_destroy(ctx, NULL);
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020035 free(data);
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010036 return 0;
37}