Commit 4bf9d240 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Fix the return value of NtQueryKey for a short buffer.

parent 41751e61
......@@ -1817,10 +1817,23 @@ static void test_NtQueryKey(void)
pNtClose(key);
return;
}
todo_wine ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryKey Failed: 0x%08lx\n", status);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryKey Failed: 0x%08lx\n", status);
info = HeapAlloc(GetProcessHeap(), 0, length);
/* non-zero buffer size, but insufficient */
len = 0;
status = pNtQueryKey(key, KeyNameInformation, info, 1, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryKey Failed: 0x%08lx\n", status);
ok(length == len, "got %ld, expected %ld\n", len, length);
len = 0;
status = pNtQueryKey(key, KeyNameInformation, info, offsetof( KEY_NAME_INFORMATION, Name ) - 1, &len);
ok(status == STATUS_BUFFER_TOO_SMALL, "NtQueryKey Failed: 0x%08lx\n", status);
ok(length == len, "got %ld, expected %ld\n", len, length);
len = 0;
status = pNtQueryKey(key, KeyNameInformation, info, offsetof( KEY_NAME_INFORMATION, Name ), &len);
ok(status == STATUS_BUFFER_OVERFLOW, "NtQueryKey Failed: 0x%08lx\n", status);
ok(length == len, "got %ld, expected %ld\n", len, length);
len = 0;
status = pNtQueryKey(key, KeyNameInformation, info, sizeof(*info), &len);
ok(status == STATUS_BUFFER_OVERFLOW, "NtQueryKey Failed: 0x%08lx\n", status);
ok(length == len, "got %ld, expected %ld\n", len, length);
......@@ -1828,6 +1841,7 @@ static void test_NtQueryKey(void)
info->NameLength, winetestpath.Length);
/* correct buffer size */
len = 0;
status = pNtQueryKey(key, KeyNameInformation, info, length, &len);
ok(status == STATUS_SUCCESS, "NtQueryKey Failed: 0x%08lx\n", status);
ok(length == len, "got %ld, expected %ld\n", len, length);
......
......@@ -268,7 +268,6 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
case KeyBasicInformation:
{
KEY_BASIC_INFORMATION keyinfo;
fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
keyinfo.LastWriteTime.QuadPart = reply->modif;
keyinfo.TitleIndex = 0;
keyinfo.NameLength = reply->namelen;
......@@ -279,7 +278,6 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
case KeyFullInformation:
{
KEY_FULL_INFORMATION keyinfo;
fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
keyinfo.LastWriteTime.QuadPart = reply->modif;
keyinfo.TitleIndex = 0;
keyinfo.ClassLength = wine_server_reply_size(reply);
......@@ -297,7 +295,6 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
case KeyNodeInformation:
{
KEY_NODE_INFORMATION keyinfo;
fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
keyinfo.LastWriteTime.QuadPart = reply->modif;
keyinfo.TitleIndex = 0;
if (reply->namelen < wine_server_reply_size(reply))
......@@ -318,7 +315,6 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
case KeyNameInformation:
{
KEY_NAME_INFORMATION keyinfo;
fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
keyinfo.NameLength = reply->namelen;
memcpy( info, &keyinfo, min( length, fixed_size ) );
break;
......@@ -327,7 +323,6 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
case KeyCachedInformation:
{
KEY_CACHED_INFORMATION keyinfo;
fixed_size = sizeof(keyinfo);
keyinfo.LastWriteTime.QuadPart = reply->modif;
keyinfo.TitleIndex = 0;
keyinfo.SubKeys = reply->subkeys;
......@@ -344,7 +339,8 @@ static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS i
break;
}
*result_len = fixed_size + reply->total;
if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
if (length < fixed_size) ret = STATUS_BUFFER_TOO_SMALL;
else if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
}
}
SERVER_END_REQ;
......
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