Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3879] URLError crashes if error has unsupported code #3891

Closed
lilyball mannequin opened this issue Feb 6, 2017 · 2 comments
Closed

[SR-3879] URLError crashes if error has unsupported code #3891

lilyball mannequin opened this issue Feb 6, 2017 · 2 comments

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Feb 6, 2017

Previous ID SR-3879
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Apple Swift version 3.1 (swiftlang-802.0.31.3 clang-802.0.30.2)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, RunTimeCrash, SDKOverlay
Assignee None
Priority Medium

md5: f69285efcb731f127ab4e37defb5f80a

Issue Description:

A new URL error was introduced, NSURLErrorAppTransportSecurityRequiresSecureConnection, but was never added to the Swift Foundation overlay. As a result, if you have an error with this code, casting to URLError and accessing the code property crashes. Given that we'll probably see other new error codes in the future, we probably shouldn't crash in this case, because even if we always update the Foundation overlay, that doesn't help apps compiled against an older SDK.

Sample program:

import Foundation

let nserr = NSError(domain: NSURLErrorDomain, code: NSURLErrorAppTransportSecurityRequiresSecureConnection, userInfo: nil)
let urlerr = nserr as! URLError
print("code:", urlerr.code)

This crashes on the access for urlerr.code.

One possible solution would be to introduce a new case other(rawValue: Int) case to handle any unknown codes. We'd also need to implement == on URLError.Code at this point as we'd lose the default impl. An alternative solution is just to default to .unknown for unknown codes, but that means throwing away the actual code which isn't great.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Feb 6, 2017

I've filed the missing NSURLErrorAppTransportSecurityRequiresSecureConnection code as SR-3881.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Feb 20, 2017

I ended up fixing this in PR #7282 as part of SR-3881, which was merged in 63b122c.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants