Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <stdbool.h> |
| 4 | |
| 5 | #include "libyang.h" |
| 6 | |
| 7 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) |
| 8 | { |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 9 | struct ly_ctx *ctx = NULL; |
| 10 | static bool log = false; |
| 11 | char *data = NULL; |
| 12 | LY_ERR err; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 13 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 14 | if (!log) { |
| 15 | ly_log_options(0); |
| 16 | log = true; |
| 17 | } |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 18 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 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 | } |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 24 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 25 | data = malloc(len + 1); |
| 26 | if (data == NULL) { |
| 27 | return 0; |
| 28 | } |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 29 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 30 | memcpy(data, buf, len); |
| 31 | data[len] = 0; |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 32 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 33 | lys_parse_mem(ctx, data, LYS_IN_YANG, NULL); |
| 34 | ly_ctx_destroy(ctx); |
| 35 | free(data); |
| 36 | return 0; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 37 | } |