From: Benjamin Berg Date: Thu, 30 Oct 2025 08:24:40 +0000 (+0100) Subject: wpa_debug: Use separate buffer for path and improve error checking X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=672da5df77220684b9bbf3de5f5411c42a1e6380;p=thirdparty%2Fhostap.git wpa_debug: Use separate buffer for path and improve error checking Using the same buffer for output and input could already result in an overlapping source and destination in snprintf. This was working fine, however, with the patch to also find tracefs, we continue to parse the buffer. In that case, the continued parsing can corrupt the found path causing an error. Fix this problem and reshuffle the code a bit to make it a bit more clear and improve the condition to skip lines that could not be parsed properly. Fixes: 0a76c7ed64de ("wpa_debug: Prefer tracefs over debugfs") Signed-off-by: Benjamin Berg --- diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c index 826a9a373..0cd94a038 100644 --- a/src/utils/wpa_debug.c +++ b/src/utils/wpa_debug.c @@ -128,6 +128,7 @@ static int syslog_priority(int level) int wpa_debug_open_linux_tracing(void) { int mounts, trace_fd; + char path[128] = {}; char buf[4096] = {}; ssize_t buflen; char *line, *tmp1; @@ -146,16 +147,20 @@ int wpa_debug_open_linux_tracing(void) } buf[buflen] = '\0'; - line = strtok_r(buf, "\n", &tmp1); - while (line) { + for (line = strtok_r(buf, "\n", &tmp1); + line; + line = strtok_r(NULL, "\n", &tmp1)) { char *tmp2, *tmp_path, *fstype; /* " ..." */ strtok_r(line, " ", &tmp2); tmp_path = strtok_r(NULL, " ", &tmp2); fstype = strtok_r(NULL, " ", &tmp2); - if (!buf[0] && fstype && os_strcmp(fstype, "debugfs") == 0) { - os_snprintf(buf, sizeof(buf) - 1, + if (!line[0] || !tmp_path || !fstype) + continue; + + if (os_strcmp(fstype, "debugfs") == 0) { + os_snprintf(path, sizeof(path) - 1, "%s/tracing/trace_marker", tmp_path); /* @@ -165,21 +170,19 @@ int wpa_debug_open_linux_tracing(void) */ } - if (fstype && os_strcmp(fstype, "tracefs") == 0) { - os_snprintf(buf, sizeof(buf) - 1, "%s/trace_marker", + if (os_strcmp(fstype, "tracefs") == 0) { + os_snprintf(path, sizeof(path) - 1, "%s/trace_marker", tmp_path); break; } - - line = strtok_r(NULL, "\n", &tmp1); } - if (!buf[0]) { + if (!path[0]) { printf("tracefs/debugfs not found\n"); return -1; } - trace_fd = open(buf, O_WRONLY); + trace_fd = open(path, O_WRONLY); if (trace_fd < 0) { printf("failed to open trace_marker file\n"); return -1;