Blame SOURCES/0011-Fix-stringop-overflow-warning.patch

3e90b9
From ed5e255c023c9b78120d9ff2246d6516f652d4b7 Mon Sep 17 00:00:00 2001
3e90b9
From: Javier Martinez Canillas <javierm@redhat.com>
3e90b9
Date: Mon, 10 Feb 2020 19:32:39 +0100
3e90b9
Subject: [PATCH] Fix stringop-overflow warning
3e90b9
3e90b9
GCC gives the following compile warning:
3e90b9
3e90b9
grubby.c: In function 'main':
3e90b9
grubby.c:4508:27: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
3e90b9
 4508 |     saved_command_line[0] = '\0';
3e90b9
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
3e90b9
grubby.c:4503:26: note: at offset 0 to an object with size 0 allocated by 'malloc' here
3e90b9
 4503 |     saved_command_line = malloc(i);
3e90b9
          |                          ^~~~~~~~~
3e90b9
cc1: all warnings being treated as errors
3e90b9
make: *** [Makefile:38: grubby.o] Error 1
3e90b9
3e90b9
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
3e90b9
---
3e90b9
 grubby.c | 35 +++++++++++++++++++----------------
3e90b9
 1 file changed, 19 insertions(+), 16 deletions(-)
3e90b9
3e90b9
diff --git a/grubby.c b/grubby.c
3e90b9
index 5ca689539cf..0c0f67a0ae5 100644
3e90b9
--- a/grubby.c
3e90b9
+++ b/grubby.c
3e90b9
@@ -4500,23 +4500,26 @@ int main(int argc, const char ** argv) {
3e90b9
     int i = 0;
3e90b9
     for (int j = 1; j < argc; j++)
3e90b9
 	i += strlen(argv[j]) + 1;
3e90b9
-    saved_command_line = malloc(i);
3e90b9
-    if (!saved_command_line) {
3e90b9
-	fprintf(stderr, "grubby: %m\n");
3e90b9
-	exit(1);
3e90b9
-    }
3e90b9
-    saved_command_line[0] = '\0';
3e90b9
-    int cmdline_len = 0, arg_len;
3e90b9
-    for (int j = 1; j < argc; j++) {
3e90b9
-	arg_len = strlen(argv[j]);
3e90b9
-	memcpy(saved_command_line + cmdline_len, argv[j], arg_len);
3e90b9
-	cmdline_len += arg_len;
3e90b9
-	if (j != argc - 1) {
3e90b9
-	    memcpy(saved_command_line + cmdline_len, " ", 1);
3e90b9
-	    cmdline_len++;
3e90b9
-	}
3e90b9
+
3e90b9
+    if (i > 0) {
3e90b9
+	    saved_command_line = malloc(i);
3e90b9
+	    if (!saved_command_line) {
3e90b9
+		    fprintf(stderr, "grubby: %m\n");
3e90b9
+		    exit(1);
3e90b9
+	    }
3e90b9
+	    saved_command_line[0] = '\0';
3e90b9
+	    int cmdline_len = 0, arg_len;
3e90b9
+	    for (int j = 1; j < argc; j++) {
3e90b9
+		    arg_len = strlen(argv[j]);
3e90b9
+		    memcpy(saved_command_line + cmdline_len, argv[j], arg_len);
3e90b9
+		    cmdline_len += arg_len;
3e90b9
+		    if (j != argc - 1) {
3e90b9
+			    memcpy(saved_command_line + cmdline_len, " ", 1);
3e90b9
+			    cmdline_len++;
3e90b9
+		    }
3e90b9
+	    }
3e90b9
+	    saved_command_line[cmdline_len] = '\0';
3e90b9
     }
3e90b9
-    saved_command_line[cmdline_len] = '\0';
3e90b9
 
3e90b9
     optCon = poptGetContext("grubby", argc, argv, options, 0);
3e90b9
     poptReadDefaultConfig(optCon, 1);
3e90b9
-- 
3e90b9
2.24.1
3e90b9