blob: f420966842ad050d7807736e9e6c24a86cc213b4 [file] [log] [blame]
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <stdbool.h>
4
Michal Vaskob9878502022-11-11 10:00:05 +01005#include "libyang.h"
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +02006
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01007int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len)
8{
Michal Vaskob9878502022-11-11 10:00:05 +01009 struct lys_module *mod;
10 uint8_t *data = NULL;
11 struct ly_ctx *ctx = NULL;
12 static bool log = false;
13 LY_ERR err;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010014
Michal Vaskob9878502022-11-11 10:00:05 +010015 if (!log) {
16 ly_log_options(0);
17 log = true;
18 }
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010019
Michal Vaskob9878502022-11-11 10:00:05 +010020 err = ly_ctx_new(NULL, 0, &ctx);
21 if (err != LY_SUCCESS) {
22 fprintf(stderr, "Failed to create new context\n");
23 return 0;
24 }
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010025
Michal Vaskob9878502022-11-11 10:00:05 +010026 data = malloc(len + 1);
27 if (data == NULL) {
28 fprintf(stderr, "Out of memory\n");
29 return 0;
30 }
31 memcpy(data, buf, len);
32 data[len] = 0;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010033
Michal Vaskob9878502022-11-11 10:00:05 +010034 lys_parse_mem(ctx, (const char *)data, LYS_IN_YANG, &mod);
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010035
Michal Vaskob9878502022-11-11 10:00:05 +010036 free(data);
37 ly_ctx_destroy(ctx);
38 return 0;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010039}