All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset()
@ 2026-08-31 16:48 John Kacur
  2026-09-01  6:18 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 2+ messages in thread
From: John Kacur @ 2026-08-31 16:48 UTC (permalink / raw)
  To: linux-rt-users; +Cc: Clark Williams, Sebastian Andrzej Siewior

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset()
  2026-08-31 16:48 [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset() John Kacur
@ 2026-09-01  6:18 ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-09-01  6:18 UTC (permalink / raw)
  To: John Kacur; +Cc: linux-rt-users, Clark Williams

On 2026-08-31 12:48:10 [-0400], John Kacur wrote:
> gcc -Wformat-truncation warns that the "%s/%s" format in open_cpuset()
> may be truncated because 'path' is unbounded:
…
> Signed-off-by: John Kacur <jkacur@redhat.com>

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-01  6:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 16:48 [PATCH] cyclicdeadline: Fix potential path truncation in open_cpuset() John Kacur
2026-09-01  6:18 ` Sebastian Andrzej Siewior

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.