From c045a1bb4be7a095a1468ad40a5a21922d218b0f Mon Sep 17 00:00:00 2001 From: Xiao Ni Date: Sat, 22 Apr 2017 22:36:01 +0800 Subject: [PATCH 1/2] Fix building errors against newer gcc(>=gcc7.0) Resolves: bz#1423932 Signed-off-by: Xiao Ni --- add-Wimplicit-fallthrough-0-in-Makefile.patch | 36 +++++++++ ...-type-conversion-to-avoid-truncation.patch | 32 ++++++++ ...-with-strncpy-at-some-places-to-avoi.patch | 58 +++++++++++++++ ...y-enough-length-when-write-to-buffer.patch | 74 +++++++++++++++++++ 4 files changed, 200 insertions(+) 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-to-avoi.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..efa5efe --- /dev/null +++ b/add-Wimplicit-fallthrough-0-in-Makefile.patch @@ -0,0 +1,36 @@ +From 8268821b434d1308d083454fb681d80176cf352b Mon Sep 17 00:00:00 2001 +From: Xiao Ni +Date: Fri, 17 Mar 2017 19:55:42 +0800 +Subject: [RHEL6.9 PATCH 1/2] 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 +--- + Makefile | 5 +++++ + 1 file changed, 5 insertions(+) + +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 +-- +2.7.4 + diff --git a/forced-type-conversion-to-avoid-truncation.patch b/forced-type-conversion-to-avoid-truncation.patch new file mode 100644 index 0000000..2a978a6 --- /dev/null +++ b/forced-type-conversion-to-avoid-truncation.patch @@ -0,0 +1,32 @@ +From 5b97512954e9710fd45ab5778bf679205c35892d Mon Sep 17 00:00:00 2001 +From: Xiao Ni +Date: Sat, 18 Mar 2017 10:33:45 +0800 +Subject: [RHEL6.9 PATCH 2/2] 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 +--- + super-intel.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +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 { +-- +2.7.4 + diff --git a/replace-snprintf-with-strncpy-at-some-places-to-avoi.patch b/replace-snprintf-with-strncpy-at-some-places-to-avoi.patch new file mode 100644 index 0000000..ee5f11a --- /dev/null +++ b/replace-snprintf-with-strncpy-at-some-places-to-avoi.patch @@ -0,0 +1,58 @@ +From 618f4e6d63c8c09d8d4002770e44617f3477f137 Mon Sep 17 00:00:00 2001 +From: Xiao Ni +Date: Sat, 18 Mar 2017 10:33:44 +0800 +Subject: [RHEL6.9 PATCH 1/2] 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 +--- + super-intel.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +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); +-- +2.7.4 + 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..cc26ec0 --- /dev/null +++ b/specify-enough-length-when-write-to-buffer.patch @@ -0,0 +1,74 @@ +From ff9239ee3177630d62c7a58408992af7a779763c Mon Sep 17 00:00:00 2001 +From: Xiao Ni +Date: Fri, 17 Mar 2017 19:55:43 +0800 +Subject: [RHEL6.9 PATCH 2/2] mdadm: Specify enough length when write to buffer +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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 +--- + Detail.c | 2 +- + super0.c | 2 +- + util.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +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, +-- +2.7.4 + From d04845eb4c396817a3f2e0e2fd86add03b982fef Mon Sep 17 00:00:00 2001 From: Xiao Ni Date: Mon, 24 Apr 2017 20:11:59 +0800 Subject: [PATCH 2/2] Update mdadm.spec for commit c045a1b Signed-off-by: Xiao Ni --- mdadm.spec | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mdadm.spec b/mdadm.spec index 203e170..263d0e1 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-to-avoi.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 +* Mon Apr 24 2017 Xiao Ni - 4.0-3 +- Fix building errors agains newer gcc(>=7.0) +- Resolves bz1423932 + * Fri Feb 10 2017 Fedora Release Engineering - 4.0-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild