summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikhil R <nikhilr5@kpit.com>2025-02-04 07:55:26 +0100
committerSteve Sakoman <steve@sakoman.com>2025-02-15 06:04:44 -0800
commit70349820ed3af4295823a73b5f74fb56f345b8ad (patch)
tree69a25ee467a5437cae6841cf4f431b57e45c8983
parent2e79f42006aaa6a222c89e22a6ee22fd7dad7ea9 (diff)
downloadpoky-70349820ed3af4295823a73b5f74fb56f345b8ad.tar.gz
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 <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com> (From OE-Core rev: 78fac0f623e01bd52b2ea3a597d056726deca8a4) Signed-off-by: Nikhil R <nikhilr5@kpit.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch61
-rw-r--r--meta/recipes-core/glibc/glibc_2.35.bb1
2 files changed, 62 insertions, 0 deletions
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 0000000000..7068a81518
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch
@@ -0,0 +1,61 @@
1From 6128e82ebe973163d2dd614d31753c88c0c4d645 Mon Sep 17 00:00:00 2001
2From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
3Date: Wed, 21 Sep 2022 10:51:07 -0300
4Subject: [PATCH] sunrpc: Suppress GCC -Os warning on user2netname
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9GCC with -Os warns that sprint might overflow:
10
11 netname.c: In function ‘user2netname’:
12 netname.c:51:28: error: ‘%s’ directive writing up to 255 bytes into a
13 region of size between 239 and 249 [-Werror=format-overflow=]
14 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom);
15 | ^~ ~~~~~~~
16 netname.c:51:3: note: ‘sprintf’ output between 8 and 273 bytes into a
17 destination of size 256
18 51 | sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom);
19 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 cc1: all warnings being treated as errors
21
22However the code does test prior the sprintf call that dfltdom plus
23the required extra space for OPSYS, uid, and extra character will not
24overflow and return 0 instead.
25
26Checked on x86_64-linux-gnu and i686-linux-gnu.
27Reviewed-by: Carlos O'Donell <carlos@redhat.com>
28Tested-by: Carlos O'Donell <carlos@redhat.com>
29
30Upstream-Status: Backport [https://github.com/bminor/glibc/commit/6128e82ebe973163d2dd614d31753c88c0c4d645]
31Signed-off-by: nikhil <nikhil.r@kpit.com>
32
33---
34 sunrpc/netname.c | 6 ++++++
35 1 file changed, 6 insertions(+)
36
37diff --git a/sunrpc/netname.c b/sunrpc/netname.c
38index bf7f0b81c43..c1d1c43e502 100644
39--- a/sunrpc/netname.c
40+++ b/sunrpc/netname.c
41@@ -20,6 +20,7 @@
42 #include <string.h>
43 #include <rpc/rpc.h>
44 #include <shlib-compat.h>
45+#include <libc-diag.h>
46
47 #include "nsswitch.h"
48
49@@ -48,7 +49,12 @@ user2netname (char netname[MAXNETNAMELEN + 1], const uid_t uid,
50 if ((strlen (dfltdom) + OPSYS_LEN + 3 + MAXIPRINT) > (size_t) MAXNETNAMELEN)
51 return 0;
52
53+ /* GCC with -Os warns that sprint might overflow while handling dfltdom,
54+ however the above test does check if an overflow would happen. */
55+ DIAG_PUSH_NEEDS_COMMENT;
56+ DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wformat-overflow");
57 sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom);
58+ DIAG_POP_NEEDS_COMMENT;
59 i = strlen (netname);
60 if (netname[i - 1] == '.')
61 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 9400e1e920..d9cae79ac2 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 \
64 \ 64 \
65 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ 65 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \
66 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ 66 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
67 file://0003-sunrpc-suppress-gcc-os-warning-on-user2netname.patch \
67 " 68 "
68S = "${WORKDIR}/git" 69S = "${WORKDIR}/git"
69B = "${WORKDIR}/build-${TARGET_SYS}" 70B = "${WORKDIR}/build-${TARGET_SYS}"