Closed AlexanderVatov closed 1 year ago
@AlexanderVatov this occurs in https://github.com/jaraco/keyring/blob/977ed03677bb0602b91f005461ef3dddf01a49f6/keyring/backends/macOS/api.py#L150 as seen below
as you can see, the function find generic password
fetches the password as ''
. however, in python, empty strings resolve as False. The if
statement therefore resolves as false and never deletes the password.
error -25299
means that an item with this identifier already exists. Of course it throws this error, as the item was never deleted!
in your code it can be protected by ensuring set passwords are len() > 1, but looking into this issue now
looking into this further. keyring.get_password has strange behaviour for getting empty passwords too. i think by luck it ends up being ''
(empty string). when it tries to call cfstr_to_str, the data it passes in is a None pointer of size 0. this resolves to b''
which is then decoded to ''
at https://github.com/jaraco/keyring/blob/main/keyring/backends/macOS/api.py#L95
thanks for the super quick review and fix @jaraco, awesome stuff!
just one question, would it be worth removing the not_found_ok
flag from find_generic_password
now that nothing else uses it?
https://github.com/jaraco/keyring/blob/main/keyring/backends/macOS/api.py#L130
and then youd also what to remove the 2 lines of code using that flag in the same function (142-143)
Describe the bug If a password is set to '', any subsequent attempts to set it to another value result in the following error:
To Reproduce
Expected behavior One would expect set_password not to be affected by previous calls of set_password.
Environment
Python 3.8.9 on macOS
Additional context Getting the blank password works fine. Deleting it and then setting it to any non-blank password also works as a workaround.