From c352788ef5d4c40aa1e85582ab4c4b82666646b2 Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Thu, 15 May 2025 13:01:46 +0200 Subject: [PATCH] fix: invalid jumps on uninitialized variable --- config.c | 4 ++-- test.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 5bca523..9777400 100644 --- a/config.c +++ b/config.c @@ -189,6 +189,8 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int case ST_FOUND_SECTION: keyName = malloc(MAX_LEN_SECTIONNAME); keyValue = malloc(MAX_LEN_SECTIONNAME); + memset(keyName,0,MAX_LEN_SECTIONNAME); + memset(keyValue,0,MAX_LEN_SECTIONNAME); if((ret=getNameValuePair(token,'=',0, &keyName,&keyValue, MAX_LEN_SECTIONNAME,MAX_LEN_SECTIONNAME @@ -225,8 +227,6 @@ int parseConfig(char *buffer,struct configEntry **entry,int configSizeCount,int } } - free(keyName); - free(keyValue); free(sectionName); return NO_ERROR; } diff --git a/test.c b/test.c index 8f4524f..2a766de 100644 --- a/test.c +++ b/test.c @@ -24,6 +24,7 @@ int main(void) { free(sectionName); printf("an error occured:%d\n",ret); + return 1; } char testpair[] = "asifdsfo=s1254124"; @@ -56,6 +57,7 @@ int main(void) return 1; } content = malloc(neededSize); + memset(content,0,neededSize); if((ret=getFile("config.cfg",&content,neededSize,&neededSize))==NO_ERROR) { printf("Sucessfull read file into buffer:%s\n---\n",content); @@ -83,7 +85,8 @@ int main(void) free(keyValue); free(keyName); free(name); - - + free(entry->keyName); + free(sectionName); + return 0; }