Repository navigation
Tags: google/GoogleUtilities
Tags
Harden GULUserDefaults getters and GULNetworkURLSession response hand… …ling (#252) * fix(userdefaults): check stored value types in typed getters The typed getters sent NSNumber selectors (integerValue, boolValue, ...) to whatever object was stored, so a persisted value of an unexpected type (e.g. an array or data written from a server response) crashed with an unrecognized selector. stringForKey:, arrayForKey: and dictionaryForKey: returned the stored object unchecked, handing callers the wrong type. Mirror NSUserDefaults: numeric getters accept NSNumber or NSString, stringForKey: converts an NSNumber to its stringValue, and the collection getters return nil for other types. * fix(network): handle non-HTTP responses and nil request URLs URLSession:task:didCompleteWithError: asserted that the task response is an NSHTTPURLResponse. The assertion is compiled out of release builds, so a non-HTTP response (possible when a custom NSURLProtocol intercepts the request) was cast and passed to callers, who then crash calling statusCode or allHeaderFields. Replace the assertion with a runtime check and report a GULErrorCodeNetworkInvalidResponse error instead. Also avoid inserting a nil request URL into the array literal used to log a server trust evaluation error. * fix(logger): look up cached os_log objects by category GULOSLogBasic stored os_log objects under the category key but looked them up by subsystem, so the cache never hit and os_log_create ran for every log message. * docs(changelog): note userdefaults, network and logger fixes * fix(network): keep system errors for non-HTTP responses When a task finished with a non-HTTP response and an error, the error was replaced with GULErrorCodeNetworkInvalidResponse. Pass the more specific system error through and only create an invalid-response error when there is none. Also fall back to the task's original request URL when logging a server trust evaluation error, so the log still names the host if _request is unset.
Harden GULUserDefaults getters and GULNetworkURLSession response hand… …ling (#252) * fix(userdefaults): check stored value types in typed getters The typed getters sent NSNumber selectors (integerValue, boolValue, ...) to whatever object was stored, so a persisted value of an unexpected type (e.g. an array or data written from a server response) crashed with an unrecognized selector. stringForKey:, arrayForKey: and dictionaryForKey: returned the stored object unchecked, handing callers the wrong type. Mirror NSUserDefaults: numeric getters accept NSNumber or NSString, stringForKey: converts an NSNumber to its stringValue, and the collection getters return nil for other types. * fix(network): handle non-HTTP responses and nil request URLs URLSession:task:didCompleteWithError: asserted that the task response is an NSHTTPURLResponse. The assertion is compiled out of release builds, so a non-HTTP response (possible when a custom NSURLProtocol intercepts the request) was cast and passed to callers, who then crash calling statusCode or allHeaderFields. Replace the assertion with a runtime check and report a GULErrorCodeNetworkInvalidResponse error instead. Also avoid inserting a nil request URL into the array literal used to log a server trust evaluation error. * fix(logger): look up cached os_log objects by category GULOSLogBasic stored os_log objects under the category key but looked them up by subsystem, so the cache never hit and os_log_create ran for every log message. * docs(changelog): note userdefaults, network and logger fixes * fix(network): keep system errors for non-HTTP responses When a task finished with a non-HTTP response and an error, the error was replaced with GULErrorCodeNetworkInvalidResponse. Pass the more specific system error through and only create an invalid-response error when there is none. Also fall back to the task's original request URL when logging a server trust evaluation error, so the log still names the host if _request is unset.
Release version 8.1.3 (#246) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
chore: bump podspec versiona and add changelog note (#241)
PreviousNext