summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2019-04-26 11:44:28 +0300
committerTor Lillqvist <tml@collabora.com>2019-04-26 12:04:20 +0300
commitdb9208d36417490ea1a0a536c701233279a49e0d (patch)
tree74b38d788f441baee9071f60829b59c06daacdfb /ios
parentd550944053cca481e3bae1e981b16a23132c0126 (diff)
tdf#124918: Don't crash on invalid URLs in the template list file
Diffstat (limited to 'ios')
-rw-r--r--ios/Mobile/AppDelegate.mm92
1 files changed, 48 insertions, 44 deletions
diff --git a/ios/Mobile/AppDelegate.mm b/ios/Mobile/AppDelegate.mm
index d01712931..d1ec58119 100644
--- a/ios/Mobile/AppDelegate.mm
+++ b/ios/Mobile/AppDelegate.mm
@@ -102,51 +102,55 @@ static void updateTemplates(NSData *data, NSURLResponse *response)
NSString *line = [NSString stringWithUTF8String:buf.data()];
NSURL *url = [NSURL URLWithString:line];
- NSString *baseName = [url lastPathComponent];
-
- NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0];
- [urlHashes addObject:hash];
-
- NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash];
-
- NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]];
-
- // If we have that template, check whether it is up-to-date
- BOOL isDirectory;
- if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] &&
- isDirectory) {
- NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy];
- [req setHTTPMethod:@"HEAD"];
- [[[NSURLSession sharedSession] dataTaskWithRequest:req
- completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
- if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
- NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"];
- NSDateFormatter *df = [[NSDateFormatter alloc] init];
- df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
- NSDate *templateDate = [df dateFromString:lastModified];
-
- NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate];
-
- if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) {
- downloadTemplate(url, fileForTemplate);
+ if (url == nil)
+ LOG_ERR("Invalid URL in template file: " << [line UTF8String]);
+ else {
+ NSString *baseName = [url lastPathComponent];
+
+ NSString *hash = [[NSData dataWithBytes:buf.data() length:length] base64EncodedStringWithOptions:0];
+ [urlHashes addObject:hash];
+
+ NSString *directoryForTemplate = [downloadedTemplates stringByAppendingString:hash];
+
+ NSURL *fileForTemplate = [NSURL fileURLWithPath:[directoryForTemplate stringByAppendingString:[@"/" stringByAppendingString:baseName]]];
+
+ // If we have that template, check whether it is up-to-date
+ BOOL isDirectory;
+ if ([[NSFileManager defaultManager] fileExistsAtPath:directoryForTemplate isDirectory:&isDirectory] &&
+ isDirectory) {
+ NSMutableURLRequest *req = [[NSURLRequest requestWithURL:url] mutableCopy];
+ [req setHTTPMethod:@"HEAD"];
+ [[[NSURLSession sharedSession] dataTaskWithRequest:req
+ completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
+ if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]] && [(NSHTTPURLResponse*)response statusCode] == 200) {
+ NSString *lastModified = [[(NSHTTPURLResponse*)response allHeaderFields] objectForKey:@"Last-Modified"];
+ NSDateFormatter *df = [[NSDateFormatter alloc] init];
+ df.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
+ NSDate *templateDate = [df dateFromString:lastModified];
+
+ NSDate *cachedTemplateDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileForTemplate path] error:nil] objectForKey:NSFileModificationDate];
+
+ if ([templateDate compare:cachedTemplateDate] == NSOrderedDescending) {
+ downloadTemplate(url, fileForTemplate);
+ }
+ } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) {
+ LOG_ERR("Failed to get HEAD of " <<
+ [[url absoluteString] UTF8String] <<
+ ": response code " << [(NSHTTPURLResponse*)response statusCode]);
+ } else if (error != nil) {
+ LOG_ERR("Failed to get HEAD of " <<
+ [[url absoluteString] UTF8String] <<
+ ": " << [[error description] UTF8String]);
+ } else {
+ LOG_ERR("Failed to get HEAD of " <<
+ [[url absoluteString] UTF8String]);
}
- } else if (error == nil && [response isKindOfClass:[NSHTTPURLResponse class]]) {
- LOG_ERR("Failed to get HEAD of " <<
- [[url absoluteString] UTF8String] <<
- ": response code " << [(NSHTTPURLResponse*)response statusCode]);
- } else if (error != nil) {
- LOG_ERR("Failed to get HEAD of " <<
- [[url absoluteString] UTF8String] <<
- ": " << [[error description] UTF8String]);
- } else {
- LOG_ERR("Failed to get HEAD of " <<
- [[url absoluteString] UTF8String]);
- }
- }] resume];
- } else {
- // Else download it.
- [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil];
- downloadTemplate(url, fileForTemplate);
+ }] resume];
+ } else {
+ // Else download it.
+ [[NSFileManager defaultManager] createDirectoryAtPath:directoryForTemplate withIntermediateDirectories:YES attributes:nil error:nil];
+ downloadTemplate(url, fileForTemplate);
+ }
}
}
}