aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMRegex.m
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2020-10-02 09:46:13 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2020-10-02 15:34:46 -0400
commit1e750858d0a3fa31bf9e591cb065dcb031677a9b (patch)
tree18555807ca59765712874922b02dc62367eee815 /Foundation/GTMRegex.m
parent845205f12d5aeb0275a59259b5c658104a7d9197 (diff)
Fix issue found via asan
Don't try to use more bytes then there are in the string.
Diffstat (limited to 'Foundation/GTMRegex.m')
-rw-r--r--Foundation/GTMRegex.m8
1 files changed, 6 insertions, 2 deletions
diff --git a/Foundation/GTMRegex.m b/Foundation/GTMRegex.m
index 38077be..3d6f96f 100644
--- a/Foundation/GTMRegex.m
+++ b/Foundation/GTMRegex.m
@@ -652,11 +652,15 @@ static NSString *const kReplacementPattern =
}
- (NSString *)description {
- return [NSString stringWithFormat:@"%@<%p> { regex=\"%@\", allSegments=%s, string=\"%.20s...\" }",
+ // `[utf8StrBuf_ bytes]` won't be null terminated, must manually ensure we
+ // don't ask for more bytes then there are.
+ NSUInteger len = (int)[utf8StrBuf_ length];
+ return [NSString stringWithFormat:@"%@<%p> { regex=\"%@\", allSegments=%s, string=\"%.*s%s\" }",
[self class], self,
regex_,
(allSegments_ ? "YES" : "NO"),
- [utf8StrBuf_ bytes]];
+ (int)(MIN(len, 20)), [utf8StrBuf_ bytes],
+ (len > 20 ? "..." : "")];
}
@end