blob: 02e0a62d603693a09dc7997e42bbab223ddf6770 [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{
Michal Vaskob9878502022-11-11 10:00:05 +01009 struct ly_ctx *ctx = NULL;
10 static bool log = false;
11 char *data = NULL;
12 LY_ERR err;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010013
Michal Vaskob9878502022-11-11 10:00:05 +010014 if (!log) {
15 ly_log_options(0);
16 log = true;
17 }
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010018
Michal Vaskob9878502022-11-11 10:00:05 +010019 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 }
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010024
Michal Vaskob9878502022-11-11 10:00:05 +010025 data = malloc(len + 1);
26 if (data == NULL) {
27 return 0;
28 }
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020029
Michal Vaskob9878502022-11-11 10:00:05 +010030 memcpy(data, buf, len);
31 data[len] = 0;
Juraj Vijtiukc496e6f2020-06-30 16:15:01 +020032
Michal Vaskob9878502022-11-11 10:00:05 +010033 lys_parse_mem(ctx, data, LYS_IN_YANG, NULL);
34 ly_ctx_destroy(ctx);
35 free(data);
36 return 0;
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010037}