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 | |
Radek Krejci | e587509 | 2020-05-13 20:42:15 +0200 | [diff] [blame] | 5 | #include "../../src/common.h" |
| 6 | #include "../../src/tree_schema_internal.h" |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 7 | |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 8 | LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, const char *data, struct lys_module *mod); |
| 9 | |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 10 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) |
| 11 | { |
| 12 | struct lys_module *mod = NULL; |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 13 | struct lys_yang_parser_ctx *context = NULL; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 14 | uint8_t *data = NULL; |
| 15 | struct ly_ctx *ctx = NULL; |
| 16 | static bool log = false; |
| 17 | LY_ERR err; |
| 18 | |
| 19 | if (!log) { |
| 20 | ly_log_options(0); |
| 21 | log = true; |
| 22 | } |
| 23 | |
| 24 | err = ly_ctx_new(NULL, 0, &ctx); |
| 25 | if (err != LY_SUCCESS) { |
| 26 | fprintf(stderr, "Failed to create new context\n"); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | data = malloc(len + 1); |
| 31 | if (data == NULL) { |
| 32 | fprintf(stderr, "Out of memory\n"); |
| 33 | return 0; |
| 34 | } |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 35 | memcpy(data, buf, len); |
Juraj Vijtiuk | c496e6f | 2020-06-30 16:15:01 +0200 | [diff] [blame] | 36 | data[len] = 0; |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 37 | |
| 38 | mod = calloc(1, sizeof *mod); |
| 39 | if (mod == NULL) { |
| 40 | fprintf(stderr, "Out of memory\n"); |
| 41 | return 0; |
| 42 | } |
| 43 | mod->ctx = ctx; |
| 44 | |
| 45 | yang_parse_module(&context, data, mod); |
| 46 | |
| 47 | free(data); |
| 48 | free(mod); |
| 49 | ly_ctx_destroy(ctx, NULL); |
| 50 | return 0; |
| 51 | } |