From 96db487a4da5903b71c64edf7a0ee9c2e01a8762 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 12 Jan 2022 14:48:55 +0100 Subject: common,w32: Improve HKCU->HKLM fallback * common/w32-reg.c (read_w32_registry_string): Add another fallback. -- We use the same method in gpgme and libgpg-error since 2017 - should be done here as well. Thus the fallback also happens if the key exists but not the actual entry. --- common/w32-reg.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/w32-reg.c b/common/w32-reg.c index fda2d1cfa..816531fd5 100644 --- a/common/w32-reg.c +++ b/common/w32-reg.c @@ -160,8 +160,18 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) } nbytes = 1; - if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) - goto leave; + if (RegQueryValueEx (key_handle, name, 0, NULL, NULL, &nbytes)) + { + if (root) + goto leave; + /* Try to fallback to HKLM also for a missing value. */ + RegCloseKey (key_handle); + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle)) + return NULL; /* Nope. */ + if (RegQueryValueEx (key_handle, name, 0, NULL, NULL, &nbytes)) + goto leave; + } + result = xtrymalloc ((n1=nbytes+1)); if (!result) goto leave; -- cgit v1.2.3