From bf6fddd70ef09d52a81c3f672b0d162edc7fdcf7 Mon Sep 17 00:00:00 2001 From: Xiao Ni Date: Wed, 26 Apr 2017 13:15:35 +0800 Subject: [PATCH] Fix building errors against newer gcc(>=7.0) Resolves: bz#144756 Signed-off-by: Xiao Ni --- add-Wimplicit-fallthrough-0-in-Makefile.patch | 31 +++++++++ ...-type-conversion-to-avoid-truncation.patch | 27 ++++++++ mdadm.spec | 14 +++- ...snprintf-with-strncpy-at-some-places.patch | 52 +++++++++++++++ ...y-enough-length-when-write-to-buffer.patch | 64 +++++++++++++++++++ 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 add-Wimplicit-fallthrough-0-in-Makefile.patch create mode 100644 forced-type-conversion-to-avoid-truncation.patch create mode 100644 replace-snprintf-with-strncpy-at-some-places.patch create mode 100644 specify-enough-length-when-write-to-buffer.patch diff --git a/add-Wimplicit-fallthrough-0-in-Makefile.patch b/add-Wimplicit-fallthrough-0-in-Makefile.patch new file mode 100644 index 0000000..74c97eb --- /dev/null +++ b/add-Wimplicit-fallthrough-0-in-Makefile.patch @@ -0,0 +1,31 @@ +commit 8268821b434d1308d083454fb681d80176cf352b +Author: Xiao Ni +Date: Fri Mar 17 19:55:42 2017 +0800 + + mdadm: Add Wimplicit-fallthrough=0 in Makefile + + There are many errors like 'error: this statement may fall through'. + But the logic is right. So add the flag Wimplicit-fallthrough=0 + to disable the error messages. The method I use is from + https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + #index-Wimplicit-fallthrough-375 + + Signed-off-by: Xiao Ni + Signed-off-by: Jes Sorensen + +diff --git a/Makefile b/Makefile +index a6f464c..d1a6ac4 100644 +--- a/Makefile ++++ b/Makefile +@@ -48,6 +48,11 @@ ifdef WARN_UNUSED + CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O3 + endif + ++FALLTHROUGH := $(shell gcc -v --help 2>&1 | grep "implicit-fallthrough" | wc -l) ++ifneq "$(FALLTHROUGH)" "0" ++CWFLAGS += -Wimplicit-fallthrough=0 ++endif ++ + ifdef DEBIAN + CPPFLAGS += -DDEBIAN + endif diff --git a/forced-type-conversion-to-avoid-truncation.patch b/forced-type-conversion-to-avoid-truncation.patch new file mode 100644 index 0000000..3d5a084 --- /dev/null +++ b/forced-type-conversion-to-avoid-truncation.patch @@ -0,0 +1,27 @@ +commit 5b97512954e9710fd45ab5778bf679205c35892d +Author: Xiao Ni +Date: Sat Mar 18 10:33:45 2017 +0800 + + mdadm: Forced type conversion to avoid truncation + + Gcc reports it needs 19 bytes to right to disk->serial. Because the + type of argument i is int. But the meaning of i is failed disk + number. So it doesn't need to use 19 bytes. Just add a type + conversion to avoid this building error + + Signed-off-by: Xiao Ni + Signed-off-by: Jes Sorensen + +diff --git a/super-intel.c b/super-intel.c +index 343f20d..e1618f1 100644 +--- a/super-intel.c ++++ b/super-intel.c +@@ -5228,7 +5228,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, + disk->status = CONFIGURED_DISK | FAILED_DISK; + disk->scsi_id = __cpu_to_le32(~(__u32)0); + snprintf((char *) disk->serial, MAX_RAID_SERIAL_LEN, +- "missing:%d", i); ++ "missing:%d", (__u8)i); + } + find_missing(super); + } else { diff --git a/mdadm.spec b/mdadm.spec index 203e170..4385252 100644 --- a/mdadm.spec +++ b/mdadm.spec @@ -1,7 +1,7 @@ Summary: The mdadm program controls Linux md devices (software RAID arrays) Name: mdadm Version: 4.0 -Release: 2%{?dist} +Release: 3%{?dist} Source: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}.tar.xz Source1: mdmonitor.init Source2: raid-check @@ -13,6 +13,10 @@ Source7: mdadm.conf Source8: mdadm_event.conf # Fedora customization patches +Patch93: add-Wimplicit-fallthrough-0-in-Makefile.patch +Patch94: forced-type-conversion-to-avoid-truncation.patch +Patch95: replace-snprintf-with-strncpy-at-some-places.patch +Patch96: specify-enough-length-when-write-to-buffer.patch Patch97: mdadm-3.3-udev.patch Patch98: mdadm-2.5.2-static.patch URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/ @@ -41,6 +45,10 @@ file can be used to help with some common tasks. %setup -q # Fedora customization patches +%patch93 -p1 -b .fallthrough +%patch94 -p1 -b .forced +%patch95 -p1 -b .replace +%patch96 -p1 -b .buffer %patch97 -p1 -b .udev %patch98 -p1 -b .static @@ -104,6 +112,10 @@ rm -rf %{buildroot} /etc/libreport/events.d/* %changelog +* Wed Apr 26 2017 Xiao Ni - 4.0-3 +- Fix building errors against newer gcc (>=7.0) +- Resolves bz1444756 + * Fri Feb 10 2017 Fedora Release Engineering - 4.0-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild diff --git a/replace-snprintf-with-strncpy-at-some-places.patch b/replace-snprintf-with-strncpy-at-some-places.patch new file mode 100644 index 0000000..dceec78 --- /dev/null +++ b/replace-snprintf-with-strncpy-at-some-places.patch @@ -0,0 +1,52 @@ +commit 618f4e6d63c8c09d8d4002770e44617f3477f137 +Author: Xiao Ni +Date: Sat Mar 18 10:33:44 2017 +0800 + + Replace snprintf with strncpy at some places to avoid truncation + + In gcc7 there are some building errors like: + directive output may be truncated writing up to 31 bytes into a region of size 24 + snprintf(str, MPB_SIG_LEN, %s, mpb->sig); + + It just need to copy one string to target. So use strncpy to replace it. + + For this line code: snprintf(str, MPB_SIG_LEN, %s, mpb->sig); + Because mpb->sig has the content of version after magic, so + it's better to use strncpy to replace snprintf too. + + Signed-off-by: Xiao Ni + Signed-off-by: Jes Sorensen + +diff --git a/super-intel.c b/super-intel.c +index d5e9517..343f20d 100644 +--- a/super-intel.c ++++ b/super-intel.c +@@ -1811,7 +1811,8 @@ static void examine_super_imsm(struct supertype *st, char *homehost) + __u32 reserved = imsm_reserved_sectors(super, super->disks); + struct dl *dl; + +- snprintf(str, MPB_SIG_LEN, "%s", mpb->sig); ++ strncpy(str, (char *)mpb->sig, MPB_SIG_LEN); ++ str[MPB_SIG_LEN-1] = '\0'; + printf(" Magic : %s\n", str); + snprintf(str, strlen(MPB_VERSION_RAID0), "%s", get_imsm_version(mpb)); + printf(" Version : %s\n", get_imsm_version(mpb)); +@@ -7142,14 +7143,16 @@ static int update_subarray_imsm(struct supertype *st, char *subarray, + + u->type = update_rename_array; + u->dev_idx = vol; +- snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name); ++ strncpy((char *) u->name, name, MAX_RAID_SERIAL_LEN); ++ u->name[MAX_RAID_SERIAL_LEN-1] = '\0'; + append_metadata_update(st, u, sizeof(*u)); + } else { + struct imsm_dev *dev; + int i; + + dev = get_imsm_dev(super, vol); +- snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name); ++ strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN); ++ dev->volume[MAX_RAID_SERIAL_LEN-1] = '\0'; + for (i = 0; i < mpb->num_raid_devs; i++) { + dev = get_imsm_dev(super, i); + handle_missing(super, dev); diff --git a/specify-enough-length-when-write-to-buffer.patch b/specify-enough-length-when-write-to-buffer.patch new file mode 100644 index 0000000..2001edb --- /dev/null +++ b/specify-enough-length-when-write-to-buffer.patch @@ -0,0 +1,64 @@ +commit ff9239ee3177630d62c7a58408992af7a779763c +Author: Xiao Ni +Date: Fri Mar 17 19:55:43 2017 +0800 + + mdadm: Specify enough length when write to buffer + + In Detail.c the buffer path in function Detail is defined as path[200], + in fact the max lenth of content which needs to write to the buffer is + 287. Because the length of dname of struct dirent is 255. + During building it reports error: + error: ā€˜%sā€™ directive writing up to 255 bytes into a region of size 189 + [-Werror=format-overflow=] + + In function examine_super0 there is a buffer nb with length 5. + But it need to show a int type argument. The lenght of max + number of int is 10. So the buffer length should be 11. + + In human_size function the length of buf is 30. During building + there is a error: + output between 20 and 47 bytes into a destination of size 30. + Change the length to 47. + + Signed-off-by: Xiao Ni + Signed-off-by: Jes Sorensen + +diff --git a/Detail.c b/Detail.c +index 509b0d4..cb33794 100644 +--- a/Detail.c ++++ b/Detail.c +@@ -575,7 +575,7 @@ This is pretty boring + printf(" Member Arrays :"); + + while (dir && (de = readdir(dir)) != NULL) { +- char path[200]; ++ char path[287]; + char vbuf[1024]; + int nlen = strlen(sra->sys_name); + dev_t devid; +diff --git a/super0.c b/super0.c +index 938cfd9..f5b4507 100644 +--- a/super0.c ++++ b/super0.c +@@ -231,7 +231,7 @@ static void examine_super0(struct supertype *st, char *homehost) + d++) { + mdp_disk_t *dp; + char *dv; +- char nb[5]; ++ char nb[11]; + int wonly, failfast; + if (d>=0) dp = &sb->disks[d]; + else dp = &sb->this_disk; +diff --git a/util.c b/util.c +index f100972..32bd909 100644 +--- a/util.c ++++ b/util.c +@@ -811,7 +811,7 @@ unsigned long calc_csum(void *super, int bytes) + #ifndef MDASSEMBLE + char *human_size(long long bytes) + { +- static char buf[30]; ++ static char buf[47]; + + /* We convert bytes to either centi-M{ega,ibi}bytes or + * centi-G{igi,ibi}bytes, with appropriate rounding,