[compiler-rt] adaf5ba - Fix possible underflow in ParseAndSetPath (#159389)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 08:11:50 PDT 2025
Author: gbMattN
Date: 2025-09-18T16:11:46+01:00
New Revision: adaf5ba6791e7b32dd6dca2f857d588a5304d7e7
URL: https://github.com/llvm/llvm-project/commit/adaf5ba6791e7b32dd6dca2f857d588a5304d7e7
DIFF: https://github.com/llvm/llvm-project/commit/adaf5ba6791e7b32dd6dca2f857d588a5304d7e7.diff
LOG: Fix possible underflow in ParseAndSetPath (#159389)
If an empty path is passed, the internal_strlen -1 below will loop round
to become uptr max. Adding this check ensures that this would be caught
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index 9236a458cdb0e..a2c0a9c39d04e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -108,6 +108,9 @@ static void ParseAndSetPath(const char *pattern, char *dest,
CHECK(dest);
CHECK_GE(dest_size, 1);
dest[0] = '\0';
+ // Return empty string if empty string was passed
+ if (internal_strlen(pattern) == 0)
+ return;
uptr next_substr_start_idx = 0;
for (uptr i = 0; i < internal_strlen(pattern) - 1; i++) {
if (pattern[i] != '%')
More information about the llvm-commits
mailing list