From aa4a14998fa76927647cb7d0acf44af384bb4186 Mon Sep 17 00:00:00 2001 From: elegantShock2258 Date: Thu, 14 Oct 2021 16:28:59 +0530 Subject: [PATCH 1/3] FIXWARN : Provided limits to sscanf(), reduced scope of cache_enabled. --- uwufetch.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 3b2546e..791d5d7 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -122,11 +122,13 @@ void remove_brackets(char *str); int main(int argc, char *argv[]) { char *cache_env = getenv("UWUFETCH_CACHE_ENABLED"); - int cache_enabled = 0; if (cache_env != NULL) - { + { + + int cache_enabled = 0; char buffer[128]; - sscanf(cache_env, "%[TRUEtrue1]", buffer); + + sscanf(cache_env, "%1[TRUEtrue1]", buffer); cache_enabled = (strcmp(buffer, "true") == 0 || strcmp(buffer, "TRUE") == 0 || strcmp(buffer, "1") == 0); if (cache_enabled) { From 8147b0a528a461a2ebef9b03597a9e4c056d134e Mon Sep 17 00:00:00 2001 From: elegantShock2258 Date: Thu, 14 Oct 2021 16:53:54 +0530 Subject: [PATCH 2/3] L:222 reduced home_dir's scope. L:318 changed to appropiate format specifier L:500 changed line's location. --- uwufetch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 791d5d7..4014b3b 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -207,7 +207,6 @@ int main(int argc, char *argv[]) void parse_config() { char line[256]; - char homedir[512]; // opening and reading the config file FILE *config=NULL; @@ -215,6 +214,7 @@ void parse_config() { if (getenv("HOME") != NULL) { + char homedir[512]; sprintf(homedir, "%s/.config/uwufetch/config", getenv("HOME")); config = fopen(homedir, "r"); } @@ -315,7 +315,7 @@ int pkgman() comma_separator++; char spkg_count[16]; - sprintf(spkg_count, "%d", pkg_count); + sprintf(spkg_count, "%u", pkg_count); strcat(pkgman_name, spkg_count); strcat(pkgman_name, " "); strcat(pkgman_name, current->pkgman_name); // this is the line that breaks mac os, but something strange happens before @@ -497,7 +497,6 @@ int read_cache() void print_cache() { - char line[256]; // ram #ifndef __APPLE__ #ifndef __CYGWIN__ @@ -508,6 +507,7 @@ void print_cache() #else meminfo = popen("LANG=EN_us free -m 2> /dev/null", "r"); #endif + char line[256]; while (fgets(line, sizeof(line), meminfo)) // free command prints like this: "Mem:" total used free shared buff/cache available sscanf(line, "Mem: %d %d", &ram_total, &ram_used); From debc5a7c058fff44c5efea495d52bb3b313c247b Mon Sep 17 00:00:00 2001 From: TheDarkBug <41623496+TheDarkBug@users.noreply.github.com> Date: Thu, 14 Oct 2021 22:39:29 +0200 Subject: [PATCH 3/3] Fixed reading "TRUE" or "true" in cache env variable --- uwufetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uwufetch.c b/uwufetch.c index 4014b3b..c38eed9 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) int cache_enabled = 0; char buffer[128]; - sscanf(cache_env, "%1[TRUEtrue1]", buffer); + sscanf(cache_env, "%4[TRUEtrue1]", buffer); cache_enabled = (strcmp(buffer, "true") == 0 || strcmp(buffer, "TRUE") == 0 || strcmp(buffer, "1") == 0); if (cache_enabled) {