From fccf05ee71dc4415b2fb0c978b3cdedd5e49c17a Mon Sep 17 00:00:00 2001 From: Christopher Engelhard Date: Mon, 21 Sep 2020 17:51:43 +0200 Subject: [PATCH] fix GCC-11 build failure, h/t Jeff Law --- 0009-fix-GCC-11-build-failure.patch | 52 +++++++++++++++++++++++++++++ sysfsutils.spec | 2 ++ 2 files changed, 54 insertions(+) create mode 100644 0009-fix-GCC-11-build-failure.patch diff --git a/0009-fix-GCC-11-build-failure.patch b/0009-fix-GCC-11-build-failure.patch new file mode 100644 index 0000000..923a125 --- /dev/null +++ b/0009-fix-GCC-11-build-failure.patch @@ -0,0 +1,52 @@ +From 840b639f9e807e1dab4e14817fe72657b9252e53 Mon Sep 17 00:00:00 2001 +From: Kamalesh Babulal +Date: Thu, 17 Sep 2020 20:31:25 +0530 +Subject: lib/sysfs_class: fix build failure reported on GCC-11 + +Christopher reported that, the build fails with GCC-11. It introduces a +-Wstringop-overread, that warns about reading past the end in string +functions. cdev_name_equal() does a comparison, which compares strings +past SYSFS_NAME_LEN. It currently calculates the string lengths of both +string and does a comparison on strings of equal length. + +This patch refactors the function to compare, the strings until +SYSFS_NAME_LEN, removing the string length comparison logic. + +Fixes #12 ("Build failure with GCC-11 due to stringop-overread") +Reported-by: Christopher Engelhard +Tested-by: Christopher Engelhard +Signed-off-by: Kamalesh Babulal +--- + lib/sysfs_class.c | 9 +-------- + 1 file changed, 1 insertion(+), 8 deletions(-) + +diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c +index fcaa488..6389892 100644 +--- a/lib/sysfs_class.c ++++ b/lib/sysfs_class.c +@@ -68,7 +68,6 @@ void sysfs_close_class(struct sysfs_class *cls) + */ + static int cdev_name_equal(void *a, void *b) + { +- size_t length_a, length_b; + char *str_a, *str_b; + + if (!a || !b) +@@ -77,13 +76,7 @@ static int cdev_name_equal(void *a, void *b) + str_a = (char *)a; + str_b = ((struct sysfs_class_device *)b)->name; + +- length_a = strnlen(str_a, SYSFS_NAME_LEN+1); +- length_b = strnlen(str_b, SYSFS_NAME_LEN+1); +- +- if (length_a != length_b) +- return 0; +- +- if (strncmp(str_a, str_b, length_a+1) == 0) ++ if (strncmp(str_a, str_b, SYSFS_NAME_LEN) == 0) + return 1; + + return 0; +-- +2.26.2 + diff --git a/sysfsutils.spec b/sysfsutils.spec index 0a9d802..157999b 100644 --- a/sysfsutils.spec +++ b/sysfsutils.spec @@ -22,6 +22,8 @@ Patch6: 0006-limit-cdev-name-length-comparsion.patch Patch7: 0007-fix-sysfs_get_link.patch # upstreamed version of formatting/typo/license-related fedora patches, PR#9 Patch8: 0008-clarify-license-fix-typos.patch +# upstream issue #12 / PR#13 +Patch9: 0009-fix-GCC-11-build-failure.patch BuildRequires: gcc