Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | #include "libyang.h" |
| 7 | |
| 8 | LY_ERR buf_add_char(struct ly_ctx *ctx, const char **input, size_t len, char **buf, size_t *buf_len, size_t *buf_used); |
| 9 | |
| 10 | int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) |
| 11 | { |
| 12 | struct ly_ctx *ctx = NULL; |
| 13 | LY_ERR err; |
| 14 | uint8_t *data = NULL; |
| 15 | uint8_t *old_data = NULL; |
| 16 | uint8_t *dest = NULL; |
| 17 | size_t dest_len = 0; |
| 18 | size_t used = 0; |
| 19 | static bool log = false; |
| 20 | |
| 21 | if (!log) { |
| 22 | ly_log_options(0); |
| 23 | log = true; |
| 24 | } |
| 25 | |
| 26 | err = ly_ctx_new(NULL, 0, &ctx); |
| 27 | if (err != LY_SUCCESS) { |
| 28 | fprintf(stderr, "Failed to create context\n"); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | data = malloc(len); |
| 33 | if (data == NULL) { |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | dest = malloc(len); |
| 38 | if (dest == NULL) { |
| 39 | return 0; |
| 40 | } |
| 41 | dest_len = len; |
| 42 | |
| 43 | memcpy(data, buf, len); |
| 44 | old_data = data; |
Juraj Vijtiuk | dba2881 | 2020-09-24 13:56:18 +0200 | [diff] [blame] | 45 | err = buf_add_char(ctx, (const char **) &data, len, (char **) &dest, &dest_len, &used); |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 46 | |
| 47 | free(old_data); |
| 48 | free(dest); |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame^] | 49 | ly_ctx_destroy(ctx); |
Juraj Vijtiuk | 260407e | 2020-03-18 10:32:13 +0100 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |