From c762d231ea864a60b5df64c0647820f47e10500f Mon Sep 17 00:00:00 2001 From: Nathan Van Fleet Date: Fri, 20 May 2022 07:22:33 -0700 Subject: [PATCH] fix(darwin): logging - potential crash due to mishandled string formats (#286) --- .../mbgl/interface/native_apple_interface.h | 4 ++-- platform/darwin/src/http_file_source.mm | 2 +- .../darwin/src/MGLNetworkConfiguration.mm | 18 ++++-------------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/platform/darwin/include/mbgl/interface/native_apple_interface.h b/platform/darwin/include/mbgl/interface/native_apple_interface.h index bcdf7b8aa..407a2e0ad 100644 --- a/platform/darwin/include/mbgl/interface/native_apple_interface.h +++ b/platform/darwin/include/mbgl/interface/native_apple_interface.h @@ -20,9 +20,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)stopDownloadEventForResponse:(NSURLResponse *)response; -- (void)debugLog:(NSString *)format, ...; +- (void)debugLog:(NSString *)message; -- (void)errorLog:(NSString *)format, ...; +- (void)errorLog:(NSString *)message; @end diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index bc01dc0f2..08f8667e3 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -286,7 +286,7 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, using Error = Response::Error; if (error) { - [MGLNativeNetworkManager.sharedManager errorLog:@"Requesting: %@ failed with error: %@", res.URL.relativePath, error]; + [MGLNativeNetworkManager.sharedManager errorLog:@"Requesting: %@ failed with error: %@", req.URL, error.debugDescription]; if (data) { response.data = diff --git a/platform/ios/platform/darwin/src/MGLNetworkConfiguration.mm b/platform/ios/platform/darwin/src/MGLNetworkConfiguration.mm index 7826881ce..ac4a23855 100644 --- a/platform/ios/platform/darwin/src/MGLNetworkConfiguration.mm +++ b/platform/ios/platform/darwin/src/MGLNetworkConfiguration.mm @@ -121,22 +121,12 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace"; [self sendEventForURLResponse:response withAction:@"cancel"]; } -- (void)debugLog:(NSString *)format, ... { - va_list formatList; - va_start(formatList, format); - NSString *formattedMessage = [[NSString alloc] initWithFormat:format arguments:formatList]; - va_end(formatList); - - MGLLogDebug(formattedMessage); +- (void)debugLog:(NSString *)message { + MGLLogDebug(message); } -- (void)errorLog:(NSString *)format, ... { - va_list formatList; - va_start(formatList, format); - NSString *formattedMessage = [[NSString alloc] initWithFormat:format arguments:formatList]; - va_end(formatList); - - MGLLogError(formattedMessage); +- (void)errorLog:(NSString *)message { + MGLLogError(message); } #pragma mark - Event management