Skip to content

Securedefaults crashing the app when unwrapping the password #26

@poml88

Description

@poml88

Very strange, since one month or so I get a few crash reports via Xcode. It looks like in SecureDefaults.swift:81 it find nil.
However in SecureDefaults.swift:79 the app should already crash via assert(). I cannot reproduce this crash so I have no idea what is causing it...

Hm, now I see that there is another !, after the data() function. Maybe that is the one that is crashing? Could it have to do with some utf8 coding? Maybe in some countries the password could be non-utf8 compatible?

I don't think I can see from the crash report what the locale could be....

    public var key: Data! {
        get {
            if _key == nil {
                assert(password != nil, "Password can't be nil!") //line 79
                _key = try? AES256.createKey(
                    password: password!.data(using: .utf8)!, //line 81
                    salt: AES256.randomSalt()
                )
            }
            return _key
        }
        set {
            _key = newValue
        }
    }
Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100199a10
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [37802]

Triggered by Thread:  0


Thread 0 name:
Thread 0 Crashed:
0   FLwatch                       	0x0000000100199a10 Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value + 0 (/<compiler-generated>:0)
1   FLwatch                       	0x0000000100199a10 SecureDefaults.key.getter + 468 (SecureDefaults.swift:81)
2   FLwatch                       	0x000000010019b4c0 SecureDefaults.decrypter.getter + 92
3   FLwatch                       	0x000000010019bb04 SecureDefaults.secretObject(forKey:) + 212 (SecureDefaults.swift:264)
4   FLwatch                       	0x000000010019a888 SecureDefaults.string(forKey:) + 16 (SecureDefaults.swift:170)
5   FLwatch                       	0x000000010019a888 @objc SecureDefaults.string(forKey:) + 68 (/<compiler-generated>:169)
6   FLwatch                       	0x000000010012beb0 specialized PhoneAppConnectView.init() + 360 (PhoneAppConnectView.swift:0)
7   FLwatch                       	0x000000010018e6c4 PhoneAppConnectView.init() + 8 (/<compiler-generated>:0)
8   FLwatch                       	0x000000010018e6c4 closure #1 in ContentView.body.getter + 1176
9   SwiftUI                       	0x000000019fe66a00 TabView.init(selection:content:) + 268 (TabView.swift:273)
10  FLwatch                       	0x000000010018e1bc ContentView.body.getter + 236 (ContentView.swift:20)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions