From: John Kacur <jkacur@redhat.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-rt-users@vger.kernel.org,
Clark Williams <williams@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH 05/10] rt-utils: Remove fileprefix.
Date: Fri, 19 Sep 2025 14:41:13 -0400 (EDT) [thread overview]
Message-ID: <73fef5ee-c88b-6ce1-0460-5d448e17bf10@redhat.com> (raw)
In-Reply-To: <20250903111717.1391196-6-bigeasy@linutronix.de>
On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:
> Remove fileprefix and use tracefs_prefix directly.
> There is no need for having both.
> Since sprintf() will complain that output buffer has the same size as
> the first input buffer so it could write more bytes use snprintf() and
> catch that possible overflow.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> src/lib/rt-utils.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 696bca2657d18..0e6e6056a4392 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -33,7 +33,6 @@
> #define MAX_TS_SIZE 64
>
> static char tracefs_prefix[MAX_PATH];
> -static char *fileprefix;
> static int trace_fd = -1;
> static int tracemark_fd = -1;
> static __thread char tracebuf[TRACEBUFSIZ];
> @@ -363,12 +362,17 @@ int parse_mem_string(char *str, uint64_t *val)
> static void open_tracemark_fd(void)
> {
> char path[MAX_PATH];
> + int n;
>
> /*
> * open the tracemark file if it's not already open
> */
> if (tracemark_fd < 0) {
> - sprintf(path, "%s/%s", fileprefix, "trace_marker");
> + n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "trace_marker");
> + if (n >= sizeof(path)) {
> + warn("tracefs path too long\n");
> + return;
> + }
> tracemark_fd = open(path, O_WRONLY);
> if (tracemark_fd < 0) {
> warn("unable to open trace_marker file: %s\n", path);
> @@ -382,7 +386,11 @@ static void open_tracemark_fd(void)
> * if we hit a breaktrace threshold
> */
> if (trace_fd < 0) {
> - sprintf(path, "%s/%s", fileprefix, "tracing_on");
> + n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "tracing_on");
> + if (n >= sizeof(path)) {
> + warn("tracefs path too long\n");
> + return;
> + }
> if ((trace_fd = open(path, O_WRONLY)) < 0)
> warn("unable to open tracing_on file: %s\n", path);
> }
> @@ -408,7 +416,7 @@ static int trace_file_exists(char *name)
>
> static void tracefs_prepare(void)
> {
> - fileprefix = get_tracefs_prefix();
> + get_tracefs_prefix();
> if (!trace_file_exists("tracing_enabled") &&
> !trace_file_exists("tracing_on"))
> warn("tracing_enabled or tracing_on not found\n"
> --
> 2.51.0
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
next prev parent reply other threads:[~2025-09-19 18:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
2025-09-19 18:18 ` John Kacur
2025-09-03 11:17 ` [PATCH 02/10] rt-utils: Remove mount_debugfs() Sebastian Andrzej Siewior
2025-09-19 18:20 ` John Kacur
2025-09-03 11:17 ` [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs Sebastian Andrzej Siewior
2025-09-19 18:29 ` John Kacur
2025-09-03 11:17 ` [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing Sebastian Andrzej Siewior
2025-09-19 18:39 ` John Kacur
2025-09-03 11:17 ` [PATCH 05/10] rt-utils: Remove fileprefix Sebastian Andrzej Siewior
2025-09-19 18:41 ` John Kacur [this message]
2025-09-03 11:17 ` [PATCH 06/10] rt-utils: Simplify trace_file_exists() Sebastian Andrzej Siewior
2025-09-19 18:42 ` John Kacur
2025-09-03 11:17 ` [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping Sebastian Andrzej Siewior
2025-09-19 18:49 ` John Kacur
2025-09-03 11:17 ` [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation Sebastian Andrzej Siewior
2025-09-19 18:52 ` John Kacur
2025-09-03 11:17 ` [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf() Sebastian Andrzej Siewior
2025-09-19 18:54 ` John Kacur
2025-09-03 11:17 ` [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features Sebastian Andrzej Siewior
2025-09-19 18:55 ` John Kacur
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=73fef5ee-c88b-6ce1-0460-5d448e17bf10@redhat.com \
--to=jkacur@redhat.com \
--cc=bigeasy@linutronix.de \
--cc=linux-rt-users@vger.kernel.org \
--cc=rostedt@goodmis.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).