From 487a599b7bbb81e8d3e802052dc4674246057349 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Tue, 4 Sep 2018 16:18:46 +0200 Subject: [PATCH] bugfix: fix memory error Using valgrind revealed that those two arrays were too small. Let's use 512 bytes, which should be enough for every practical cases. --- common/config/config_cmdline.c | 25 ++++++---------------- common/config/libconfig/config_libconfig.c | 13 ++--------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c index c9b1c32378..ba04fbb281 100644 --- a/common/config/config_cmdline.c +++ b/common/config/config_cmdline.c @@ -141,25 +141,16 @@ char defbool[2]="1"; int config_process_cmdline(paramdef_t *cfgoptions,int numoptions, char *prefix) { - - -int c = config_get_if()->argc; -int i,j; -char *pp; -char *cfgpath; + int c = config_get_if()->argc; + int i,j; + char *pp; + char cfgpath[512]; /* 512 should be enough for the sprintf below */ - j = (prefix ==NULL) ? 0 : strlen(prefix); - cfgpath = malloc( j + MAX_OPTNAME_SIZE +1); - if (cfgpath == NULL) { - fprintf(stderr,"[CONFIG] %s %i malloc error, %s\n", __FILE__, __LINE__,strerror(errno)); - return -1; - } - j = 0; i = 0; while (c > 0 ) { char *oneargv = strdup(config_get_if()->argv[i]); /* we use strtok_r which modifies its string paramater, and we don't want argv to be modified */ -/* first check help options, either --help, -h or --help_
*/ + /* first check help options, either --help, -h or --help_
*/ if (strncmp(oneargv, "-h",2) == 0 || strncmp(oneargv, "--help",6) == 0 ) { char *tokctx; pp=strtok_r(oneargv, "_",&tokctx); @@ -182,7 +173,7 @@ char *cfgpath; } } -/* now, check for non help options */ + /* now, check for non help options */ if (oneargv[0] == '-') { for(int n=0;n