From 569107579eafcdd181260880c7ea051bfe5c9322 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 10 Jun 2020 11:33:15 +0200 Subject: [PATCH] Fix cliparser buffer allocation --- client/deps/cliparser/cliparser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/deps/cliparser/cliparser.c b/client/deps/cliparser/cliparser.c index f0ba57d40..3eaec2b55 100644 --- a/client/deps/cliparser/cliparser.c +++ b/client/deps/cliparser/cliparser.c @@ -11,6 +11,9 @@ #include "cliparser.h" #include #include +#ifndef ARRAYLEN +# define ARRAYLEN(x) (sizeof(x)/sizeof((x)[0])) +#endif int CLIParserInit(CLIParserContext **ctx, const char *vprogramName, const char *vprogramHint, const char *vprogramHelp) { *ctx = malloc(sizeof(CLIParserContext)); @@ -88,15 +91,14 @@ int CLIParserParseStringEx(CLIParserContext *ctx, const char *str, void *vargtab char *argv[200] = {NULL}; int len = strlen(str); - char buf[500] = {0}; - memset(ctx->buf, 0x00, 500); - char *bufptr = buf; + memset(ctx->buf, 0x00, ARRAYLEN(ctx->buf)); + char *bufptr = ctx->buf; char *spaceptr = NULL; enum ParserState state = PS_FIRST; argv[argc++] = bufptr; // param0 = program name - memcpy(buf, ctx->programName, strlen(ctx->programName) + 1); // with 0x00 + memcpy(ctx->buf, ctx->programName, strlen(ctx->programName) + 1); // with 0x00 bufptr += strlen(ctx->programName) + 1; if (len) argv[argc++] = bufptr;