1 Upstream-Status: Backport
2 Signed-off-by: Ross Burton <ross.burton@arm.com>
4 From b0422e9e5a539164af75cddcaeb01bceca56bf12 Mon Sep 17 00:00:00 2001
5 From: "Frank Ch. Eigler" <fche@redhat.com>
6 Date: Thu, 13 Jan 2022 18:33:15 -0500
7 Subject: [PATCH] PR28778: gcc warning tweak for sprintf precision parameter
9 A precision=-1 sentinel value got interpreted as UINT_MAX in a
10 context, leading to diagnostics like:
12 /usr/share/systemtap/runtime/vsprintf.c:341:23: error: 'strnlen' specified bound 4294967295 may exceed maximum object size 2147483647 [-Werror=stringop-overread]
14 Adding a clamp_t() around the parameter field to keep it limited to
15 STP_BUFFER_SIZE (8K by default), which is apprx. the limit for a
18 runtime/vsprintf.c | 4 ++--
19 1 file changed, 2 insertions(+), 2 deletions(-)
21 diff --git a/runtime/vsprintf.c b/runtime/vsprintf.c
22 index cd31a938b..606f685e8 100644
23 --- a/runtime/vsprintf.c
24 +++ b/runtime/vsprintf.c
25 @@ -338,7 +338,7 @@ _stp_vsprint_memory(char * str, char * end, const char * ptr,
27 if ((unsigned long)ptr < PAGE_SIZE)
29 - len = strnlen(ptr, precision);
30 + len = strnlen(ptr, clamp_t(size_t, precision, 0, STP_BUFFER_SIZE));
32 else if (precision > 0)
34 @@ -410,7 +410,7 @@ _stp_vsprint_memory_size(const char * ptr, int width, int precision,
36 if ((unsigned long)ptr < PAGE_SIZE)
38 - len = strnlen(ptr, precision);
39 + len = strnlen(ptr, clamp_t(size_t, precision, 0, STP_BUFFER_SIZE));
41 else if (precision > 0)