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 | { |
| 9 | struct ly_ctx *ctx = NULL; |
| 10 | static bool log = false; |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 11 | char *data = NULL; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 12 | 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 Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 25 | data = malloc(len + 1); |
| 26 | if (data == NULL) { |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | memcpy(data, buf, len); |
| 31 | data[len] = 0; |
| 32 | |
| 33 | lys_parse_mem(ctx, data, LYS_IN_YANG); |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 34 | ly_ctx_destroy(ctx, NULL); |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 35 | free(data); |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |