diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-23 09:41:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-23 11:00:43 +0000 |
commit | d0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af (patch) | |
tree | 7ea7c5e622a5d7c9c989057a1eca8954c4d7fefb /tests/fuzz/yang_parse_module.c | |
parent | Initial commit. (diff) | |
download | libyang3-d0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af.tar.xz libyang3-d0b1bae8c5c70c5d06f3dcecc450a75e7f7cb5af.zip |
Adding upstream version 3.1.0+dfsg.upstream/3.1.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/fuzz/yang_parse_module.c')
-rw-r--r-- | tests/fuzz/yang_parse_module.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/fuzz/yang_parse_module.c b/tests/fuzz/yang_parse_module.c new file mode 100644 index 0000000..f420966 --- /dev/null +++ b/tests/fuzz/yang_parse_module.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> + +#include "libyang.h" + +int LLVMFuzzerTestOneInput(uint8_t const *buf, size_t len) +{ + struct lys_module *mod; + uint8_t *data = NULL; + struct ly_ctx *ctx = NULL; + static bool log = false; + LY_ERR err; + + if (!log) { + ly_log_options(0); + log = true; + } + + err = ly_ctx_new(NULL, 0, &ctx); + if (err != LY_SUCCESS) { + fprintf(stderr, "Failed to create new context\n"); + return 0; + } + + data = malloc(len + 1); + if (data == NULL) { + fprintf(stderr, "Out of memory\n"); + return 0; + } + memcpy(data, buf, len); + data[len] = 0; + + lys_parse_mem(ctx, (const char *)data, LYS_IN_YANG, &mod); + + free(data); + ly_ctx_destroy(ctx); + return 0; +} |