From 68652c90f3747ac9e4cf83bc68e407cffaf92bb9 Mon Sep 17 00:00:00 2001 From: yang_zhuang_zhuang <1162011203@qq.com> Date: Fri, 30 Jul 2021 14:22:58 +0800 Subject: [PATCH] fix build failed with gcc 10 --- ...port-Fix-maybe-uninitialized-warning.patch | 35 +++++++++ backport-Fix-stringop-overflow-warning.patch | 73 +++++++++++++++++++ grubby.spec | 8 +- 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-maybe-uninitialized-warning.patch create mode 100644 backport-Fix-stringop-overflow-warning.patch diff --git a/backport-Fix-maybe-uninitialized-warning.patch b/backport-Fix-maybe-uninitialized-warning.patch new file mode 100644 index 0000000..1d726ba --- /dev/null +++ b/backport-Fix-maybe-uninitialized-warning.patch @@ -0,0 +1,35 @@ +From 99d10a31cee89eb45ac0743f484018d36500ce66 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 10 Feb 2020 20:08:42 +0100 +Subject: [PATCH] Fix maybe-uninitialized warning + +GCC gives the following compile warning: + +grubby.c: In function 'suseGrubConfGetBoot': +grubby.c:2770:5: error: 'grubDevice' may be used uninitialized in this function [-Werror=maybe-uninitialized] + 2770 | free(grubDevice); + | ^~~~~~~~~~~~~~~~ +cc1: all warnings being treated as errors +make: *** [Makefile:38: grubby.o] Error 1 + +Signed-off-by: Javier Martinez Canillas +--- + grubby.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/grubby.c b/grubby.c +index 5de935d..74befea 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2896,7 +2896,7 @@ int grubGetBootFromDeviceMap(const char * device, + } + + int suseGrubConfGetBoot(const char * path, char ** bootPtr) { +- char * grubDevice; ++ char * grubDevice = NULL; + + if (suseGrubConfGetInstallDevice(path, &grubDevice)) + dbgPrintf("error looking for grub installation device\n"); +-- +1.8.3.1 + diff --git a/backport-Fix-stringop-overflow-warning.patch b/backport-Fix-stringop-overflow-warning.patch new file mode 100644 index 0000000..2320496 --- /dev/null +++ b/backport-Fix-stringop-overflow-warning.patch @@ -0,0 +1,73 @@ +From c693d9d1f7b0ee4d5fa5fbbeafce3a9fbacbce52 Mon Sep 17 00:00:00 2001 +From: Javier Martinez Canillas +Date: Mon, 10 Feb 2020 18:15:26 +0100 +Subject: [PATCH] Fix stringop-overflow warning + +GCC gives the following compile warning: + +grubby.c: In function 'main': +grubby.c:4508:27: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] + 4508 | saved_command_line[0] = '\0'; + | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~ +grubby.c:4503:26: note: at offset 0 to an object with size 0 allocated by 'malloc' here + 4503 | saved_command_line = malloc(i); + | ^~~~~~~~~ +cc1: all warnings being treated as errors +make: *** [Makefile:38: grubby.o] Error 1 + +Signed-off-by: Javier Martinez Canillas +--- + grubby.c | 33 ++++++++++++++++++--------------- + 1 file changed, 18 insertions(+), 15 deletions(-) + +diff --git a/grubby.c b/grubby.c +index b8115dd..5de935d 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -4675,24 +4675,27 @@ int main(int argc, const char ** argv) { + int i = 0; + for (int j = 1; j < argc; j++) + i += strlen(argv[j]) + 1; +- saved_command_line = malloc(i); +- if (!saved_command_line) { +- fprintf(stderr, "grubby: %m\n"); +- exit(1); +- } +- saved_command_line[0] = '\0'; +- int cmdline_len = 0, arg_len; +- for (int j = 1; j < argc; j++) { +- arg_len = strlen(argv[j]); +- memcpy(saved_command_line + cmdline_len, argv[j], arg_len); +- cmdline_len += arg_len; +- if (j != argc - 1) { +- memcpy(saved_command_line + cmdline_len, " ", 1); +- cmdline_len++; +- } ++ if (i > 0) { ++ saved_command_line = malloc(i); ++ if (!saved_command_line) { ++ fprintf(stderr, "grubby: %m\n"); ++ exit(1); ++ } ++ ++ saved_command_line[0] = '\0'; ++ int cmdline_len = 0, arg_len; ++ for (int j = 1; j < argc; j++) { ++ arg_len = strlen(argv[j]); ++ memcpy(saved_command_line + cmdline_len, argv[j], arg_len); ++ cmdline_len += arg_len; ++ if (j != argc - 1) { ++ memcpy(saved_command_line + cmdline_len, " ", 1); ++ cmdline_len++; ++ } ++ } ++ saved_command_line[cmdline_len] = '\0'; + + } +- saved_command_line[cmdline_len] = '\0'; + + optCon = poptGetContext("grubby", argc, argv, options, 0); + poptReadDefaultConfig(optCon, 1); +-- +1.8.3.1 + diff --git a/grubby.spec b/grubby.spec index b2cba9c..aea8b74 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 27 +Release: 28 Summary: Update and display information about the configuration files License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -30,6 +30,8 @@ Patch6012: Fix-GCC-warnings-about-possible-string-truncations-a.patch Patch6013: Check-that-pointers-are-not-NULL-before-dereferencin.patch Patch6014: Print-default-image-even-if-isn-t-a-suitable-one.patch Patch6015: backport-Make-SET_VARIABLE-get-handled-individually-in-GetNex.patch +Patch6016: backport-Fix-stringop-overflow-warning.patch +Patch6017: backport-Fix-maybe-uninitialized-warning.patch Patch9001: fix-make-test-fail-when-no-boot-partition.patch Patch9002: Fix-make-test-fail-for-g2-1.15.patch @@ -107,6 +109,10 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} > %{buildroo %{_mandir}/man8/*.8* %changelog +* Fri Jul 30 2021 yangzhuangzhuang - 8.40-28 +- Fix stringop-overflow warning +- Fix maybe-uninitialized warning + * Thu Jul 22 2021 yangzhuangzhuang - 8.40-27 - Remove unnecessary buildrequires:gdb