russhwolf / multiplatform-settings

A Kotlin Multiplatform library for saving simple key-value data
Apache License 2.0
1.49k stars 64 forks source link

Fix crash when creating 'KeychainSettings' without name on mac. #175

Closed MJegorovas closed 7 months ago

MJegorovas commented 7 months ago

There is an edge case with creating KeychainSettings on Mac with no name and calling keys variable. Because kSecAttrService is not set you get a bunch of random values which might not have kSecAttrAccount set so the call fails with NullPointerException. Not sure if the fix style and new test assertion work for you, just wanted to raise the issue. Tested on m2 mac.

russhwolf commented 7 months ago

Thanks. I don't completely understand what happens here but I see that we can sometimes get null returns from CFDictionaryGetValue which I didn't realize would actually happen in practice. I should have done more testing when adding the parameterless constructor because it's a little different/dangerous how it picks up everything and we can't make as many assumptions about the data that's in there.

russhwolf commented 7 months ago

Pushed some edits. Sorry that it kills some of the code you had in the git blame, but I'll leave the commits separate so you don't completely lose credit.