From 760d15b4d0128e75a7e5f09c1629b348dea837ad Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Fri, 17 Jul 2026 21:19:15 +0200 Subject: [PATCH 1/2] oscompat: harden path_is_absolute against empty strings The Windows branch reads path[1] guarded only by short-circuit evaluation, which is correct at runtime but trips -Warray-bounds when the function is inlined with a string literal shorter than two bytes, as the oscompat unit tests do with "". It also passes a plain char to isalpha(), which is undefined behavior for negative values. Return early for the empty string, so the path[1] access is provably in bounds, and feed isalpha() an unsigned char. Signed-off-by: Igor Opaniuk --- src/oscompat.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oscompat.h b/src/oscompat.h index 0b0c8b90..0e7a8dba 100644 --- a/src/oscompat.h +++ b/src/oscompat.h @@ -44,7 +44,9 @@ static inline bool path_is_absolute(const char *path) #ifndef _WIN32 return path[0] == '/'; #else - return (isalpha(path[0]) && path[1] == ':') || + if (path[0] == '\0') + return false; + return (isalpha((unsigned char)path[0]) && path[1] == ':') || (path[0] == '\\' && path[1] == '\\'); #endif } From fd0e86d54295ac49aacdd666ae71f5fc555b8e1a Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Fri, 17 Jul 2026 21:19:15 +0200 Subject: [PATCH 2/2] tests: warn and skip overly-long paths in rmtree rmtree() concatenates the directory path and entry name into a PATH_MAX buffer without checking for truncation, which -Wformat- truncation flags on the Windows build where PATH_MAX is 260. A truncated path would also make the cleanup delete the wrong file in principle. Check the snprintf() result and skip entries that do not fit; using the return value also satisfies the warning. A skipped entry means the parent rmdir() fails with ENOTEMPTY and the workdir lingers, so report the skip on stderr instead of hiding it - the message names the entry, making a leftover workdir traceable to its cause. Signed-off-by: Igor Opaniuk --- tests/test_oscompat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_oscompat.c b/tests/test_oscompat.c index 9ee5bb27..189adbfb 100644 --- a/tests/test_oscompat.c +++ b/tests/test_oscompat.c @@ -39,7 +39,13 @@ static void rmtree(const char *path) if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue; - snprintf(child, sizeof(child), "%s/%s", path, ent->d_name); + if (snprintf(child, sizeof(child), "%s/%s", path, + ent->d_name) >= (int)sizeof(child)) { + fprintf(stderr, + "skipping overly-long path %s/%s\n", + path, ent->d_name); + continue; + } if (stat(child, &st) == 0 && S_ISDIR(st.st_mode)) rmtree(child); else