Commit 1590b1f7 authored by Sam Dennis's avatar Sam Dennis Committed by Alexandre Julliard

advapi32: Fix undocumented behaviour in ReqQueryValueEx when 'count' and 'type'…

advapi32: Fix undocumented behaviour in ReqQueryValueEx when 'count' and 'type' point to the same address.
parent 5fa90ca9
...@@ -1217,7 +1217,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO ...@@ -1217,7 +1217,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
{ {
NTSTATUS status; NTSTATUS status;
ANSI_STRING nameA; ANSI_STRING nameA;
DWORD total_size; DWORD total_size, datalen = 0;
char buffer[256], *buf_ptr = buffer; char buffer[256], *buf_ptr = buffer;
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer; KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ); static const int info_size = offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data );
...@@ -1228,6 +1228,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO ...@@ -1228,6 +1228,7 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER; if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE; if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
if (count) datalen = *count;
if (!data && count) *count = 0; if (!data && count) *count = 0;
/* this matches Win9x behaviour - NT sets *type to a random value */ /* this matches Win9x behaviour - NT sets *type to a random value */
...@@ -1270,21 +1271,21 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO ...@@ -1270,21 +1271,21 @@ LSTATUS WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWO
total_size - info_size ); total_size - info_size );
if (data && len) if (data && len)
{ {
if (len > *count) status = STATUS_BUFFER_OVERFLOW; if (len > datalen) status = STATUS_BUFFER_OVERFLOW;
else else
{ {
RtlUnicodeToMultiByteN( (char*)data, len, NULL, (WCHAR *)(buf_ptr + info_size), RtlUnicodeToMultiByteN( (char*)data, len, NULL, (WCHAR *)(buf_ptr + info_size),
total_size - info_size ); total_size - info_size );
/* if the type is REG_SZ and data is not 0-terminated /* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \0 */ * and there is enough space in the buffer NT appends a \0 */
if (len < *count && data[len-1]) data[len] = 0; if (len < datalen && data[len-1]) data[len] = 0;
} }
} }
total_size = len + info_size; total_size = len + info_size;
} }
else if (data) else if (data)
{ {
if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW; if (total_size - info_size > datalen) status = STATUS_BUFFER_OVERFLOW;
else memcpy( data, buf_ptr + info_size, total_size - info_size ); else memcpy( data, buf_ptr + info_size, total_size - info_size );
} }
} }
......
...@@ -580,6 +580,10 @@ static void test_query_value_ex(void) ...@@ -580,6 +580,10 @@ static void test_query_value_ex(void)
ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size); ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret); ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size); ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
size = 4;
ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
} }
static void test_get_value(void) static void test_get_value(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment