[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[qemu-s390x] [PULL 1/7] trace: handle tracefs path truncation
From: |
Stefan Hajnoczi |
Subject: |
[qemu-s390x] [PULL 1/7] trace: handle tracefs path truncation |
Date: |
Mon, 25 Mar 2019 15:58:51 +0000 |
If the tracefs mountpoint has a very long path we may exceed PATH_MAX.
This is a system misconfiguration and the user must resolve it so that
applications can perform path-based system calls successfully.
This issue does not occur on real-world systems since tracefs is mounted
on /sys/kernel/debug/tracing/, but the compiler is smart enough to
foresee the possibility and warn about the unchecked snprintf(3) return
value. This patch fixes the compiler warning.
Reported-by: Markus Armbruster <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Liam Merwick <address@hidden>
Message-id: address@hidden
Message-Id: <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
trace/ftrace.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/trace/ftrace.c b/trace/ftrace.c
index 61692a8682..9749543d9b 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -53,7 +53,11 @@ bool ftrace_init(void)
}
if (tracefs_found) {
- snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir);
+ if (snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir)
+ >= sizeof(path)) {
+ fprintf(stderr, "Using tracefs mountpoint would exceed
PATH_MAX\n");
+ return false;
+ }
trace_fd = open(path, O_WRONLY);
if (trace_fd < 0) {
if (errno == EACCES) {
@@ -72,7 +76,11 @@ bool ftrace_init(void)
}
close(trace_fd);
}
- snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir);
+ if (snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir)
+ >= sizeof(path)) {
+ fprintf(stderr, "Using tracefs mountpoint would exceed
PATH_MAX\n");
+ return false;
+ }
trace_marker_fd = open(path, O_WRONLY);
if (trace_marker_fd < 0) {
perror("Could not open ftrace 'trace_marker' file");
--
2.20.1
- [qemu-s390x] [PULL 0/7] Tracing patches, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 7/7] trace-events: Fix attribution of trace points to source, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 6/7] trace-events: Delete unused trace points, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 4/7] trace-events: Shorten file names in comments, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 5/7] scripts/cleanup-trace-events: Update for current practice, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 3/7] trace-events: Consistently point to docs/devel/tracing.txt, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 2/7] trace: avoid SystemTap dtrace(1) warnings on empty files, Stefan Hajnoczi, 2019/03/25
- [qemu-s390x] [PULL 1/7] trace: handle tracefs path truncation,
Stefan Hajnoczi <=
- Re: [qemu-s390x] [PULL 0/7] Tracing patches, Peter Maydell, 2019/03/25