[PATCH 1/2] trace-cmd: libtrace-cmd: fix glob() return value checks

Johannes Berg <[email protected]> Thu, 3 Jul 2025 13:53:34 +0200
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
glob() is defined to return zero on success or various GLOB_*
error constants, but those are not defined to be negative. In
fact, glibc makes them positive, and as a result the checks
don't do anything at all on glibc, but erroneously abort on
other libc implementations (such as bionic) that use negative
values for GLOB_* errors.

Fix this to compare against 0 only, adding documentation as
to which error result codes are possible.

Fixes: 3de68e3ec662 ("trace-cmd: Only record the formats of the events being recorded")
Signed-off-by: Johannes Berg <[email protected]>
---
 lib/trace-cmd/trace-output.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 00b87a196c16..c333553ebf67 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -882,7 +882,8 @@ static void glob_events(struct tracecmd_output *handle,
 	globbuf.gl_offs = 0;
 	ret = glob(path, 0, NULL, &globbuf);
 	free(path);
-	if (ret < 0)
+	/* no request flags, so only GLOB_NOSPACE and GLOB_NOMATCH */
+	if (ret != 0)
 		return;
 
 	for (i = 0; i < globbuf.gl_pathc; i++) {
-- 
2.50.0