From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1] perf header: Ensure read strings are '\0' terminated
Date: Tue, 14 Apr 2026 21:17:32 +0000 [thread overview]
Message-ID: <20260414211732.A8664C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260414205725.2211169-1-irogers@google.com>
Sashiko AI review found 1 potential issue(s):
- [Medium] Casting the unsigned 32-bit length to a signed `int` causes integer underflow and logic failures for large lengths.
--
commit 684fd164d75fdb623faa938c77daf911d959b273
Author: Ian Rogers <irogers@google.com>
perf header: Ensure read strings are '\0' terminated
This commit adds a check to do_read_string() to ensure that strings read
from perf data are correctly '\0' terminated. If the string is not
correctly terminated or if the length is zero, it returns NULL.
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
[ ... ]
> @@ -269,7 +272,10 @@ static char *do_read_string(struct feat_fd *ff)
> * thus the actual strlen of buf
> * may be less than len
> */
> - return buf;
> + for (int i = (int)len - 1; i >= 0; i--) {
Could this explicit cast of the unsigned 32-bit length to a signed int
cause integer underflow and logic failures for large lengths?
Since do_read_u32() reads the 32-bit unsigned integer len directly from
the perf data file, a length greater than 2GB (e.g., 0x80000001) would
result in a negative number when cast to int.
Would this cause the loop condition i >= 0 to evaluate to false
immediately, skipping the null-terminator check and rejecting the string
by returning NULL?
Additionally, if len is exactly 0x80000000, would subtracting 1 cause
signed integer underflow?
> + if (buf[i] == '\0')
> + return buf;
> + }
> }
>
> free(buf);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260414205725.2211169-1-irogers@google.com?part=1
next prev parent reply other threads:[~2026-04-14 21:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 20:57 [PATCH v1] perf header: Ensure read strings are '\0' terminated Ian Rogers
2026-04-14 21:15 ` David Laight
2026-04-14 21:17 ` sashiko-bot [this message]
2026-04-14 21:21 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260414211732.A8664C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox