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

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