[PATCH 3/4] ntdll: Write a null terminator in NtQueryDirectoryObject.
Zebediah Figura
zfigura at codeweavers.com
Tue Apr 12 19:11:41 CDT 2022
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/ntdll/tests/om.c | 18 ++++++++----------
dlls/ntdll/unix/sync.c | 19 ++++++++++++++-----
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index 89cd2b8e3f4..e3524d07a70 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -2532,7 +2532,7 @@ static void test_query_directory(void)
status = NtQueryDirectoryObject( dir, info, 0, TRUE, TRUE, &context, &size );
ok( status == STATUS_NO_MORE_ENTRIES, "got %#lx\n", status );
ok( context == 0xdeadbeef, "got context %#lx\n", context );
- todo_wine ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
+ ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
context = 0xdeadbeef;
size = 0xdeadbeef;
@@ -2547,9 +2547,8 @@ static void test_query_directory(void)
status = NtQueryDirectoryObject( dir, info, sizeof(buffer), TRUE, TRUE, &context, &size );
ok( status == STATUS_NO_MORE_ENTRIES, "got %#lx\n", status );
ok( context == 0xdeadbeef, "got context %#lx\n", context );
- todo_wine ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
- if (size == sizeof(*info))
- ok( !memcmp( &info[0], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
+ ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
+ ok( !memcmp( &info[0], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
context = 0xdeadbeef;
size = 0xdeadbeef;
@@ -2600,8 +2599,7 @@ static void test_query_directory(void)
}
check_unicode_string( &info[0].ObjectName, name1 );
check_unicode_string( &info[0].ObjectTypeName, L"Mutant" );
- todo_wine
- ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
+ ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
memset( buffer, 0xcc, sizeof(buffer) );
status = NtQueryDirectoryObject( dir, info, sizeof(buffer), TRUE, FALSE, &context, &size );
@@ -2609,13 +2607,13 @@ static void test_query_directory(void)
ok( context == 2, "got context %#lx\n", context );
check_unicode_string( &info[0].ObjectName, name2 );
check_unicode_string( &info[0].ObjectTypeName, L"Mutant" );
- todo_wine ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
+ ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
size = 0xdeadbeef;
status = NtQueryDirectoryObject( dir, info, sizeof(buffer), TRUE, FALSE, &context, &size );
ok( status == STATUS_NO_MORE_ENTRIES, "got %#lx\n", status );
ok( context == 2, "got context %#lx\n", context );
- todo_wine ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
+ ok( size == sizeof(*info) || broken(!size) /* WoW64 */, "got size %lu\n", size );
memset( buffer, 0xcc, sizeof(buffer) );
status = NtQueryDirectoryObject( dir, info, sizeof(buffer), TRUE, TRUE, &context, &size );
@@ -2623,7 +2621,7 @@ static void test_query_directory(void)
ok( context == 1, "got context %#lx\n", context );
check_unicode_string( &info[0].ObjectName, name1 );
check_unicode_string( &info[0].ObjectTypeName, L"Mutant" );
- todo_wine ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
+ ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
needed_size = size;
@@ -2650,7 +2648,7 @@ static void test_query_directory(void)
ok( context == 1, "got context %#lx\n", context );
check_unicode_string( &info[0].ObjectName, name1 );
check_unicode_string( &info[0].ObjectTypeName, L"Mutant" );
- todo_wine ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
+ ok( !memcmp( &info[1], &empty_info, sizeof(*info) ), "entry was not cleared\n" );
memset( buffer, 0xcc, sizeof(buffer) );
status = NtQueryDirectoryObject( dir, info, sizeof(buffer), FALSE, TRUE, &context, &size );
diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c
index efbe363c210..1695e6ed570 100644
--- a/dlls/ntdll/unix/sync.c
+++ b/dlls/ntdll/unix/sync.c
@@ -1108,14 +1108,14 @@ NTSTATUS WINAPI NtQueryDirectoryObject( HANDLE handle, DIRECTORY_BASIC_INFORMATI
{
req->handle = wine_server_obj_handle( handle );
req->index = index;
- if (size >= sizeof(*buffer) + 2 * sizeof(WCHAR))
- wine_server_set_reply( req, buffer + 1, size - sizeof(*buffer) - 2 * sizeof(WCHAR) );
+ if (size >= 2 * sizeof(*buffer) + 2 * sizeof(WCHAR))
+ wine_server_set_reply( req, buffer + 2, size - 2 * sizeof(*buffer) - 2 * sizeof(WCHAR) );
if (!(ret = wine_server_call( req )))
{
- buffer->ObjectName.Buffer = (WCHAR *)(buffer + 1);
+ buffer->ObjectName.Buffer = (WCHAR *)(buffer + 2);
buffer->ObjectName.Length = reply->name_len;
buffer->ObjectName.MaximumLength = reply->name_len + sizeof(WCHAR);
- buffer->ObjectTypeName.Buffer = (WCHAR *)(buffer + 1) + reply->name_len/sizeof(WCHAR) + 1;
+ buffer->ObjectTypeName.Buffer = (WCHAR *)(buffer + 2) + reply->name_len/sizeof(WCHAR) + 1;
buffer->ObjectTypeName.Length = wine_server_reply_size( reply ) - reply->name_len;
buffer->ObjectTypeName.MaximumLength = buffer->ObjectTypeName.Length + sizeof(WCHAR);
/* make room for the terminating null */
@@ -1123,11 +1123,20 @@ NTSTATUS WINAPI NtQueryDirectoryObject( HANDLE handle, DIRECTORY_BASIC_INFORMATI
buffer->ObjectTypeName.Length );
buffer->ObjectName.Buffer[buffer->ObjectName.Length/sizeof(WCHAR)] = 0;
buffer->ObjectTypeName.Buffer[buffer->ObjectTypeName.Length/sizeof(WCHAR)] = 0;
+
+ memset( &buffer[1], 0, sizeof(buffer[1]) );
+
*context = index + 1;
}
+ else if (ret == STATUS_NO_MORE_ENTRIES)
+ {
+ if (size > sizeof(*buffer))
+ memset( buffer, 0, sizeof(*buffer) );
+ if (ret_size) *ret_size = sizeof(*buffer);
+ }
if (ret_size && (!ret || ret == STATUS_BUFFER_TOO_SMALL))
- *ret_size = sizeof(*buffer) + reply->total_len + 2 * sizeof(WCHAR);
+ *ret_size = 2 * sizeof(*buffer) + reply->total_len + 2 * sizeof(WCHAR);
}
SERVER_END_REQ;
}
--
2.34.1
More information about the wine-devel
mailing list