From 27db7ece88c6368a65547671d5210c6f2a3f2e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Tue, 9 Sep 2025 21:41:56 +0200 Subject: [PATCH] [MSGINA] ReadRegDwordValue(): Support interpreting REG_SZ values as DWORDs when possible (#8381) This is useful for numerical values that are documented as being stored in string format as `REG_SZ` in the registry; the reason being that they are still read or written via `GetProfileIntW()`/`WriteProfileStringW()` by Windows' Winlogon, and these functions store `REG_SZ` values because of the INI <-> Registry mapping mechanism. --- dll/win32/msgina/utils.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/dll/win32/msgina/utils.c b/dll/win32/msgina/utils.c index fd9a0b7089c..0fe5b349c96 100644 --- a/dll/win32/msgina/utils.c +++ b/dll/win32/msgina/utils.c @@ -94,15 +94,34 @@ ReadRegDwordValue( { LONG rc; DWORD dwValue, dwType, cbData; + /* Buffer big enough to hold the NULL-terminated string L"4294967295", + * corresponding to the literal 0xFFFFFFFF (MAXULONG) in decimal. */ + WCHAR Buffer[sizeof("4294967295")]; + C_ASSERT(sizeof(Buffer) >= sizeof(DWORD)); - cbData = sizeof(dwValue); - rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&dwValue, &cbData); + cbData = sizeof(Buffer); + rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&Buffer, &cbData); if (rc != ERROR_SUCCESS) return rc; - if (dwType != REG_DWORD) + + if (dwType == REG_DWORD) + { + if (cbData != sizeof(dwValue)) + return ERROR_INVALID_DATA; // ERROR_DATATYPE_MISMATCH; + dwValue = *(PDWORD)Buffer; + } + else if (dwType == REG_SZ) + { + PWCHAR pEnd = NULL; + Buffer[cbData / sizeof(WCHAR) - 1] = UNICODE_NULL; + dwValue = wcstoul(Buffer, &pEnd, 0); + if (*pEnd) // Don't consider REG_SZ to be supported in this case! + return ERROR_UNSUPPORTED_TYPE; + } + else + { return ERROR_UNSUPPORTED_TYPE; - if (cbData != sizeof(dwValue)) - return ERROR_INVALID_DATA; // ERROR_DATATYPE_MISMATCH; + } *pValue = dwValue; return ERROR_SUCCESS;