From 19fceff5cb30dcb69942c6a04f4decf765180e8d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 30 Oct 2012 16:59:22 -0400 Subject: [PATCH] avoid comparisons that extend past the string length (cherry picked from commit 21ee23e7dfb10510d83a7ac081050215d215dcf2) --- SoObjects/SOGo/NSString+Utilities.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index da5a69993..5a37812b3 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -134,15 +134,16 @@ static int cssEscapingCount; start--; start++; + length = [self length]; // In [UIxMailPartTextViewer flatContentAsString], we first escape HTML entities and then // add URLs. Therefore, the brackets (inequality signs <>) have been encoded at this point. - if ([[self substringWithRange: NSMakeRange (start, 4)] compare: @"<"] == NSOrderedSame) + if (length > (start + 4) + && [[self substringWithRange: NSMakeRange (start, 4)] compare: @"<"] == NSOrderedSame) start += 4; - length = [self length] - start; - workRange = NSMakeRange (start, length); + length -= start; workRange = [self rangeOfCharacterFromSet: urlAfterEndingChars - options: NSLiteralSearch range: workRange]; + options: NSLiteralSearch range: NSMakeRange (start, length)]; if (workRange.location != NSNotFound) length = workRange.location - start; while