From 88cae05301cd261ca0a4c48fceb960e2e0a200b6 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Tue, 10 Mar 2020 15:18:25 +0000 Subject: [PATCH 1/2] Fix overflow warning message. Use sizeof to determine suitable string size for the dmidecode cmd buffer --- src/logging.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/logging.c b/src/logging.c index bd1f1cf3..3c75f27f 100644 --- a/src/logging.c +++ b/src/logging.c @@ -395,7 +395,6 @@ int nwipe_log_sysinfo() { FILE* fp; char path[256]; - char cmd[50]; int len; int r; // A result buffer. @@ -428,6 +427,11 @@ int nwipe_log_sysinfo() "processor-frequency", "" // terminates the keyword array. DO NOT REMOVE }; + + char dmidecode_command[] = "dmidecode -s %s"; + + char cmd[sizeof(dmidecode_keywords)+sizeof(dmidecode_command)]; + unsigned int keywords_idx; keywords_idx = 0; @@ -435,7 +439,7 @@ int nwipe_log_sysinfo() /* Run the dmidecode command to retrieve each dmidecode keyword, one at a time */ while( dmidecode_keywords[keywords_idx][0] != 0 ) { - sprintf( cmd, "dmidecode -s %s", &dmidecode_keywords[keywords_idx][0] ); + sprintf( cmd, dmidecode_command, &dmidecode_keywords[keywords_idx][0] ); fp = popen( cmd, "r" ); if( fp == NULL ) { From 87199a194005a9ae62e3bc035ce0ac67e3c097ac Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Tue, 10 Mar 2020 15:23:18 +0000 Subject: [PATCH 2/2] Clang formatting. --- src/logging.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logging.c b/src/logging.c index 3c75f27f..aefb3907 100644 --- a/src/logging.c +++ b/src/logging.c @@ -427,10 +427,10 @@ int nwipe_log_sysinfo() "processor-frequency", "" // terminates the keyword array. DO NOT REMOVE }; - + char dmidecode_command[] = "dmidecode -s %s"; - char cmd[sizeof(dmidecode_keywords)+sizeof(dmidecode_command)]; + char cmd[sizeof( dmidecode_keywords ) + sizeof( dmidecode_command )]; unsigned int keywords_idx;