From: John Kacur <jkacur@redhat.com>
To: linux-rt-users@vger.kernel.org
Cc: Clark Williams <williams@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset()
Date: Mon, 31 Aug 2026 12:48:10 -0400 [thread overview]
Message-ID: <20260831164810.65457-1-jkacur@redhat.com> (raw)
gcc -Wformat-truncation warns that the "%s/%s" format in open_cpuset()
may be truncated because 'path' is unbounded:
cyclicdeadline.c:293:39: warning: '/' directive output may be truncated
writing 1 byte into a region of size between 0 and 1023
The existing idiom passed MAXPATH - 1 as the size and then manually
NUL-terminated the last byte, which silently proceeded with a truncated
path (leading to a stat()/open() on the wrong path) and left the warning
unaddressed.
Use the full buffer size (snprintf() always NUL-terminates within it) and
check the return value for truncation, returning an error to the caller,
which already handles a negative return.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: John Kacur <jkacur@redhat.com>
---
src/sched_deadline/cyclicdeadline.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index f97344035ca3..ff3356a9be3e 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -289,8 +289,9 @@ static int open_cpuset(const char *path, const char *name)
int ret;
int fd;
- buf[MAXPATH - 1] = 0;
- snprintf(buf, MAXPATH - 1, "%s/%s", path, name);
+ ret = snprintf(buf, sizeof(buf), "%s/%s", path, name);
+ if (ret < 0 || ret >= (int)sizeof(buf))
+ return -1;
ret = stat(buf, &st);
if (ret < 0)
--
2.55.0
next reply other threads:[~2026-08-31 16:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 16:48 John Kacur [this message]
2026-09-01 6:18 ` [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset() Sebastian Andrzej Siewior
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=20260831164810.65457-1-jkacur@redhat.com \
--to=jkacur@redhat.com \
--cc=bigeasy@linutronix.de \
--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 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.