fix(secure_storage): fix silent error swallowing in GError handling - #242
fix(secure_storage): fix silent error swallowing in GError handling#242aki1770-del wants to merge 1 commit into
Conversation
|
Please don't merge this one — I've moved it to draft. The change makes a dead A keyring failure would go from returning a wrong answer to ending the homescreen process. On a head unit that is worse than the bug. The silent success is also not in the file this PR touches: Nothing needed from you. Reworking it against |
std::unique_ptr<GError> err initialized to nullptr, followed by GError* errPtr = err.get(), produces errPtr == nullptr. GLib APIs write the new GError* into *&errPtr (a local variable), not into the unique_ptr. The unique_ptr remains null; if (err) is always false: libsecret errors are silently swallowed, the function may return true on failure, and any GError allocated by libsecret is never freed. Brings keyring.h into line with the GError* + g_clear_error pattern already used in flatpak_shim.cc and video_player.cc in this repo. Applied to both storeToKeyring and readFromKeyring. Fixes toyota-connected#230 Signed-off-by: Akihiko Komada <aki1770@gmail.com>
6620807 to
cf96cb3
Compare
Problem
keyring.huses the following pattern instoreToKeyringandreadFromKeyring:errPtr = err.get()copies the null pointer value into a local variable.GLib writes a newly-allocated
GError*into*(&errPtr)— the localvariable — not into the
unique_ptr. Theunique_ptris never updated.Consequences:
true(success) when the underlying operation failedGError*written intoerrPtrby libsecret is leakedFixes #230
Changes
File:
plugins/secure_storage/keyring.hMethods:
storeToKeyring,readFromKeyringReplace
std::unique_ptr<GError> err + GError* errPtrwith a plainGError* err, pass&errdirectly to the libsecret API, copy themessage string before
g_clear_error, then throw.This brings
keyring.hinto line with theGError*pattern alreadyused in this repo —
flatpak_shim.cc(two sites) andvideo_player.cc(one site). No new pattern is introduced.
Fix Pattern
Verification
errremains null — behavior unchanged from the caller'sperspective
erris correctly set by libsecret; message is copied beforeg_clear_errorfrees the struct;g_clear_errorresolves the memory leak;exception is thrown with the correct message
std::runtime_errorare unaffected — exception contractis unchanged
Signed-off-by: aki1770-del aki1770@gmail.com