blob: 33ca22243171f18e9022801e1e829a2beacbd785 [file] [log] [blame]
Juraj Vijtiuk260407e2020-03-18 10:32:13 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <stdbool.h>
5
6#include "libyang.h"
7
8LY_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
10int 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 Vijtiukdba28812020-09-24 13:56:18 +020045 err = buf_add_char(ctx, (const char **) &data, len, (char **) &dest, &dest_len, &used);
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010046
47 free(old_data);
48 free(dest);
49 ly_ctx_destroy(ctx, NULL);
50
51 return 0;
52}