From: John Kacur <jkacur@redhat.com>
To: linux-rt-users@vger.kernel.org
Cc: Derek Barbosa <debarbos@redhat.com>,
Clark Williams <williams@redhat.com>,
"Luis Claudio R . Goncalves" <lclaudio@uudg.org>
Subject: [PATCH 5/5] pi_stress: Ensure null-termination of JSON filename
Date: Tue, 30 Jun 2026 12:45:02 -0400 [thread overview]
Message-ID: <20260630164502.95740-6-jkacur@redhat.com> (raw)
In-Reply-To: <20260630164502.95740-1-jkacur@redhat.com>
The --json option used strncpy() with strnlen() to copy the filename,
but did not guarantee null-termination if the input string was exactly
MAX_PATH-1 characters long. When strncpy() copies exactly n characters,
it does not add a null terminator, potentially causing undefined
behavior when the string is later used.
Replace the strnlen() call with MAX_PATH-1 as the copy limit and
explicitly null-terminate the buffer to ensure the string is always
properly terminated regardless of input length.
Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/pi_tests/pi_stress.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
index 45ccac739646..500b10d60737 100644
--- a/src/pi_tests/pi_stress.c
+++ b/src/pi_tests/pi_stress.c
@@ -1238,7 +1238,8 @@ void process_command_line(int argc, char **argv)
pi_info("doing %d inversion per group\n", inversions);
break;
case OPT_JSON:
- strncpy(jsonfile, optarg, strnlen(optarg, MAX_PATH-1));
+ strncpy(jsonfile, optarg, MAX_PATH-1);
+ jsonfile[MAX_PATH-1] = '\0';
break;
case OPT_MLOCKALL:
case 'm':
--
2.54.0
prev parent reply other threads:[~2026-06-30 16:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 16:44 [PATCH 0/5] pi_stress: Bug fixes and improvements John Kacur
2026-06-30 16:44 ` [PATCH 1/5] pi_stress: Fix inconsistent barrier wait logic to prevent deadlock John Kacur
2026-06-30 16:44 ` [PATCH 2/5] pi_stress: Validate numeric command-line arguments John Kacur
2026-06-30 16:45 ` [PATCH 3/5] pi_stress: Improve error message for permission failures John Kacur
2026-06-30 16:45 ` [PATCH 4/5] pi_stress: Fix error and debug message formatting John Kacur
2026-06-30 16:45 ` John Kacur [this message]
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=20260630164502.95740-6-jkacur@redhat.com \
--to=jkacur@redhat.com \
--cc=debarbos@redhat.com \
--cc=lclaudio@uudg.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=williams@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).