From 78fac0f623e01bd52b2ea3a597d056726deca8a4 Mon Sep 17 00:00:00 2001 From: Nikhil R Date: Tue, 4 Feb 2025 07:55:26 +0100 Subject: [PATCH] glibc: Suppress GCC -Os warning on user2netname for sunrpc When building with GCC -Os, a warning is triggered indicating that sprintf might overflow. Error: netname.c: In function 'user2netname': netname.c:51:28: error: '%s' directive writing up to 255 bytes into a region of size between 239 and 249 [-Werror=format-overflow=] 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); | ^~ ~~~~~~~ netname.c:51:3: note: 'sprintf' output between 8 and 273 bytes into a destination of size 256 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors However the code does test prior the sprintf call that dfltdom plus the required extra space for OPSYS, uid, and extra character will not overflow and return 0 instead. Upstream-patch: https://github.com/bminor/glibc/commit/6128e82ebe973163d2dd614d31753c88c0c4d645 Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell Signed-off-by: Nikhil R Signed-off-by: Steve Sakoman --- ...press-gcc-os-warning-on-user2netname.patch | 61 +++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 62 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch diff --git a/meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch b/meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch new file mode 100644 index 00000000000..7068a81518f --- /dev/null +++ b/meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch @@ -0,0 +1,61 @@ +From 6128e82ebe973163d2dd614d31753c88c0c4d645 Mon Sep 17 00:00:00 2001 +From: Adhemerval Zanella Netto +Date: Wed, 21 Sep 2022 10:51:07 -0300 +Subject: [PATCH] sunrpc: Suppress GCC -Os warning on user2netname +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +GCC with -Os warns that sprint might overflow: + + netname.c: In function ‘user2netname’: + netname.c:51:28: error: ‘%s’ directive writing up to 255 bytes into a + region of size between 239 and 249 [-Werror=format-overflow=] + 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); + | ^~ ~~~~~~~ + netname.c:51:3: note: ‘sprintf’ output between 8 and 273 bytes into a + destination of size 256 + 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + cc1: all warnings being treated as errors + +However the code does test prior the sprintf call that dfltdom plus +the required extra space for OPSYS, uid, and extra character will not +overflow and return 0 instead. + +Checked on x86_64-linux-gnu and i686-linux-gnu. +Reviewed-by: Carlos O'Donell +Tested-by: Carlos O'Donell + +Upstream-Status: Backport [https://github.com/bminor/glibc/commit/6128e82ebe973163d2dd614d31753c88c0c4d645] +Signed-off-by: nikhil + +--- + sunrpc/netname.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/sunrpc/netname.c b/sunrpc/netname.c +index bf7f0b81c43..c1d1c43e502 100644 +--- a/sunrpc/netname.c ++++ b/sunrpc/netname.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + + #include "nsswitch.h" + +@@ -48,7 +49,12 @@ user2netname (char netname[MAXNETNAMELEN + 1], const uid_t uid, + if ((strlen (dfltdom) + OPSYS_LEN + 3 + MAXIPRINT) > (size_t) MAXNETNAMELEN) + return 0; + ++ /* GCC with -Os warns that sprint might overflow while handling dfltdom, ++ however the above test does check if an overflow would happen. */ ++ DIAG_PUSH_NEEDS_COMMENT; ++ DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wformat-overflow"); + sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom); ++ DIAG_POP_NEEDS_COMMENT; + i = strlen (netname); + if (netname[i - 1] == '.') + netname[i - 1] = '\0'; diff --git a/meta/recipes-core/glibc/glibc_2.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb index 9400e1e9208..d9cae79ac2f 100644 --- a/meta/recipes-core/glibc/glibc_2.35.bb +++ b/meta/recipes-core/glibc/glibc_2.35.bb @@ -64,6 +64,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ + file://0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch \ " S = "${WORKDIR}/git" B = "${WORKDIR}/build-${TARGET_SYS}" -- 2.47.3