Skip to content

Commit 27db7ec

Browse files
committed
[MSGINA] ReadRegDwordValue(): Support interpreting REG_SZ values as DWORDs when possible (reactos#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.
1 parent 01872b8 commit 27db7ec

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

dll/win32/msgina/utils.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,34 @@ ReadRegDwordValue(
9494
{
9595
LONG rc;
9696
DWORD dwValue, dwType, cbData;
97+
/* Buffer big enough to hold the NULL-terminated string L"4294967295",
98+
* corresponding to the literal 0xFFFFFFFF (MAXULONG) in decimal. */
99+
WCHAR Buffer[sizeof("4294967295")];
100+
C_ASSERT(sizeof(Buffer) >= sizeof(DWORD));
97101

98-
cbData = sizeof(dwValue);
99-
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&dwValue, &cbData);
102+
cbData = sizeof(Buffer);
103+
rc = RegQueryValueExW(hKey, pszValue, NULL, &dwType, (PBYTE)&Buffer, &cbData);
100104
if (rc != ERROR_SUCCESS)
101105
return rc;
102-
if (dwType != REG_DWORD)
106+
107+
if (dwType == REG_DWORD)
108+
{
109+
if (cbData != sizeof(dwValue))
110+
return ERROR_INVALID_DATA; // ERROR_DATATYPE_MISMATCH;
111+
dwValue = *(PDWORD)Buffer;
112+
}
113+
else if (dwType == REG_SZ)
114+
{
115+
PWCHAR pEnd = NULL;
116+
Buffer[cbData / sizeof(WCHAR) - 1] = UNICODE_NULL;
117+
dwValue = wcstoul(Buffer, &pEnd, 0);
118+
if (*pEnd) // Don't consider REG_SZ to be supported in this case!
119+
return ERROR_UNSUPPORTED_TYPE;
120+
}
121+
else
122+
{
103123
return ERROR_UNSUPPORTED_TYPE;
104-
if (cbData != sizeof(dwValue))
105-
return ERROR_INVALID_DATA; // ERROR_DATATYPE_MISMATCH;
124+
}
106125

107126
*pValue = dwValue;
108127
return ERROR_SUCCESS;

0 commit comments

Comments
 (0)