From 8c3821c75efdb27ef8e052cc2f0279c5651d2a9a Mon Sep 17 00:00:00 2001 From: project-repo Date: Sun, 24 May 2020 18:14:38 +0200 Subject: [PATCH] Add line length check to fuzzing infrastructure --- fuzz/fuzz-parse.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fuzz/fuzz-parse.c b/fuzz/fuzz-parse.c index bcfb701..a53883d 100644 --- a/fuzz/fuzz-parse.c +++ b/fuzz/fuzz-parse.c @@ -416,9 +416,13 @@ set_configuration(struct cg_server *server, char *content) { int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - char *str = malloc(size * sizeof(char) + 1); - strncpy(str, (char *)data, size); - str[size] = 0; + if(size == 0) { + return 0; + } + int max_line_size=256>size?size:256; + char *str = malloc(sizeof(char)*max_line_size); + strncpy(str, (char *)data, max_line_size); + str[max_line_size-1] = 0; set_configuration(&server, str); free(str); keybinding_list_free(server.keybindings);