All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] systemtap: fix vsprintf errors
@ 2022-01-14 18:04 Ross Burton
  0 siblings, 0 replies; only message in thread
From: Ross Burton @ 2022-01-14 18:04 UTC (permalink / raw)
  To: openembedded-core

In some configurations (such as 32-bit arm), using printf() causes
gcc errors.  Backport a patch from upstream to fix this.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 ...ing-tweak-for-sprintf-precision-para.patch | 45 +++++++++++++++++++
 .../systemtap/systemtap_git.inc               |  1 +
 2 files changed, 46 insertions(+)
 create mode 100644 meta/recipes-kernel/systemtap/systemtap/0001-PR28778-gcc-warning-tweak-for-sprintf-precision-para.patch

diff --git a/meta/recipes-kernel/systemtap/systemtap/0001-PR28778-gcc-warning-tweak-for-sprintf-precision-para.patch b/meta/recipes-kernel/systemtap/systemtap/0001-PR28778-gcc-warning-tweak-for-sprintf-precision-para.patch
new file mode 100644
index 00000000000..0801cb57ece
--- /dev/null
+++ b/meta/recipes-kernel/systemtap/systemtap/0001-PR28778-gcc-warning-tweak-for-sprintf-precision-para.patch
@@ -0,0 +1,45 @@
+Upstream-Status: Backport
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+
+From b0422e9e5a539164af75cddcaeb01bceca56bf12 Mon Sep 17 00:00:00 2001
+From: "Frank Ch. Eigler" <fche@redhat.com>
+Date: Thu, 13 Jan 2022 18:33:15 -0500
+Subject: [PATCH] PR28778: gcc warning tweak for sprintf precision parameter
+
+A precision=-1 sentinel value got interpreted as UINT_MAX in a
+context, leading to diagnostics like:
+
+/usr/share/systemtap/runtime/vsprintf.c:341:23: error: 'strnlen' specified bound 4294967295 may exceed maximum object size 2147483647 [-Werror=stringop-overread]
+
+Adding a clamp_t() around the parameter field to keep it limited to
+STP_BUFFER_SIZE (8K by default), which is apprx. the limit for a
+single printf.
+---
+ runtime/vsprintf.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c
+index cd31a938b..606f685e8 100644
+--- a/runtime/vsprintf.c
++++ b/runtime/vsprintf.c
+@@ -338,7 +338,7 @@ _stp_vsprint_memory(char * str, char * end, const char * ptr,
+ 	if (format == 's') {
+ 		if ((unsigned long)ptr < PAGE_SIZE)
+ 			ptr = "<NULL>";
+-		len = strnlen(ptr, precision);
++		len = strnlen(ptr, clamp_t(size_t, precision, 0, STP_BUFFER_SIZE));                
+ 	}
+ 	else if (precision > 0)
+ 		len = precision;
+@@ -410,7 +410,7 @@ _stp_vsprint_memory_size(const char * ptr, int width, int precision,
+ 	if (format == 's') {
+ 		if ((unsigned long)ptr < PAGE_SIZE)
+ 			ptr = "<NULL>";
+-		len = strnlen(ptr, precision);
++		len = strnlen(ptr, clamp_t(size_t, precision, 0, STP_BUFFER_SIZE));
+ 	}
+ 	else if (precision > 0)
+ 		len = precision;
+-- 
+2.25.1
+
diff --git a/meta/recipes-kernel/systemtap/systemtap_git.inc b/meta/recipes-kernel/systemtap/systemtap_git.inc
index 22b07f15165..36c934c2fa7 100644
--- a/meta/recipes-kernel/systemtap/systemtap_git.inc
+++ b/meta/recipes-kernel/systemtap/systemtap_git.inc
@@ -7,6 +7,7 @@ SRC_URI = "git://sourceware.org/git/systemtap.git;branch=master \
            file://0001-Do-not-let-configure-write-a-python-location-into-th.patch \
            file://0001-Install-python-modules-to-correct-library-dir.patch \
            file://0001-staprun-stapbpf-don-t-support-installing-a-non-root.patch \
+           file://0001-PR28778-gcc-warning-tweak-for-sprintf-precision-para.patch \
            "
 
 COMPATIBLE_HOST = '(x86_64|i.86|powerpc|arm|aarch64|microblazeel|mips).*-linux'
-- 
2.25.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-14 18:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 18:04 [PATCH] systemtap: fix vsprintf errors Ross Burton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.