Skip to content
Snippets Groups Projects
Commit fd985831 authored by Stefan Hajnoczi's avatar Stefan Hajnoczi
Browse files

trace: handle tracefs path truncation


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: default avatarMarkus Armbruster <armbru@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarLiam Merwick <liam.merwick@oracle.com>
Message-id: 20190321170831.6539-2-stefanha@redhat.com
Message-Id: <20190321170831.6539-2-stefanha@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent d97a39d9
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment