From 309020c64c25b416e84fc10ab4006707ddbebd5e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 11 Apr 2020 20:41:05 +0200 Subject: [PATCH] more error messages when failing parsing --- client/cliparser/cliparser.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/cliparser/cliparser.c b/client/cliparser/cliparser.c index 02746c0f4..4e0fb4d9c 100644 --- a/client/cliparser/cliparser.c +++ b/client/cliparser/cliparser.c @@ -38,6 +38,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable if (arg_nullcheck(argtable) != 0) { /* NULL entries were detected, some allocations must have failed */ printf("ERROR: Insufficient memory\n"); + fflush(stdout); return 2; } /* Parse the command line as defined by argtable[] */ @@ -54,6 +55,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable if (programHelp) printf("%s \n", programHelp); + fflush(stdout); return 1; } @@ -62,7 +64,7 @@ int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtable /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName); printf("Try '%s --help' for more information.\n", programName); - + fflush(stdout); return 3; } @@ -155,18 +157,24 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int int ibuf = 0; uint8_t tmp_buf[256] = {0}; int res = CLIParamStrToBuf(argstr, tmp_buf, maxdatalen * 2, &ibuf); // *2 because here HEX - if (res || !ibuf) + if (res || !ibuf){ + printf("Parameter error: buffer overflow.\n"); + fflush(stdout); return res; - + } + switch (param_gethex_to_eol((char *)tmp_buf, 0, data, maxdatalen, datalen)) { case 1: printf("Parameter error: Invalid HEX value.\n"); + fflush(stdout); return 1; case 2: printf("Parameter error: parameter too large.\n"); + fflush(stdout); return 2; case 3: printf("Parameter error: Hex string must have even number of digits.\n"); + fflush(stdout); return 3; }