Skip to content

Conversation

gbMattN
Copy link
Contributor

@gbMattN gbMattN commented Sep 17, 2025

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

@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (gbMattN)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/159389.diff

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_file.cpp (+1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index 9236a458cdb0e..49a44fa76fc9e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -106,6 +106,7 @@ static void ParseAndSetPath(const char *pattern, char *dest,
                             const uptr dest_size) {
   CHECK(pattern);
   CHECK(dest);
+  CHECK_NE(internal_strcmp(pattern, ""), 0);
   CHECK_GE(dest_size, 1);
   dest[0] = '\0';
   uptr next_substr_start_idx = 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of crashing on the empty string, I think it's better to simply return here so that dest becomes "".

@gbMattN gbMattN requested a review from ellishg September 18, 2025 14:12
@gbMattN gbMattN force-pushed the sanitizer_file_underflow branch from a2db400 to 6a4853f Compare September 18, 2025 15:10
@gbMattN gbMattN merged commit adaf5ba into llvm:main Sep 18, 2025
7 of 9 checks passed
@gbMattN gbMattN deleted the sanitizer_file_underflow branch September 18, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants