Skip to content

Commit adaf5ba

Browse files
authored
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
1 parent 9b681ea commit adaf5ba

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_file.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ static void ParseAndSetPath(const char *pattern, char *dest,
108108
CHECK(dest);
109109
CHECK_GE(dest_size, 1);
110110
dest[0] = '\0';
111+
// Return empty string if empty string was passed
112+
if (internal_strlen(pattern) == 0)
113+
return;
111114
uptr next_substr_start_idx = 0;
112115
for (uptr i = 0; i < internal_strlen(pattern) - 1; i++) {
113116
if (pattern[i] != '%')

0 commit comments

Comments
 (0)