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 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 5 | #include "libyang.h" |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 6 | |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 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 lys_module *mod; |
| 10 | uint8_t *data = NULL; |
| 11 | struct ly_ctx *ctx = NULL; |
| 12 | static bool log = false; |
| 13 | LY_ERR err; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 14 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 15 | if (!log) { |
| 16 | ly_log_options(0); |
| 17 | log = true; |
| 18 | } |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 19 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 20 | 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 Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 25 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 26 | 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 Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 33 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 34 | lys_parse_mem(ctx, (const char *)data, LYS_IN_YANG, &mod); |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 35 | |
Michal Vasko | b987850 | 2022-11-11 10:00:05 +0100 | [diff] [blame] | 36 | free(data); |
| 37 | ly_ctx_destroy(ctx); |
| 38 | return 0; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 39 | } |