Yubico / yubikit-ios

Yubico Mobile iOS SDK - YubiKit
Apache License 2.0
195 stars 43 forks source link

Fix for crash on iOS 15 when scanning OTP over NFC #79

Closed jensutbult closed 2 years ago

jensutbult commented 2 years ago

Fixes crash on iOS 15 where readerSession:didInvalidateWithError: was called twice when reading a Yubico OTP over NFC. This would happen if the user pressed cancel, sent the app to the background and then opened the app again.

The crash can not be reproduces running our automated tests which is why no new tests that validates the fix has been added. There's however a test project available here: https://github.com/jensutbult/OTP-Crash

Closes #78

leitlia commented 2 years ago

Interesting thing, when I tried to validate the crash, then I played around with different solutions, and this line if (self.nfcOTPResponseBlock) still caused crash I think because of the nature of C level blocks. And the explicit nil checking fixed the condition (if (self.nfcOTPResponseBlock == nil)). For my understanding the objc_msgSend is missing from the Obj-C Block mechanism, and that's why it is vulnerable to calling them when they are nil.