[PATCH 3/3] ntdll: Return failure from RtlQueryProcessDebugInformation.

Rémi Bernon rbernon at codeweavers.com
Thu Nov 26 03:11:36 CST 2020


When PID is invalid, some DRMs call it with GetCurrentThreadId().

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

They don't seem to mind about the result though, and they don't seem
to do anything meaningful with the buffer either. What is supposed to be
exposed in it, isn't very clear anyway. Our structures definitions may
be incorrect or outdated, or this API is broken on Windows too.

 dlls/ntdll/debugbuffer.c | 13 +++++++++++--
 dlls/ntdll/tests/rtl.c   | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/debugbuffer.c b/dlls/ntdll/debugbuffer.c
index 3ac765d454e..e6b16bbb880 100644
--- a/dlls/ntdll/debugbuffer.c
+++ b/dlls/ntdll/debugbuffer.c
@@ -114,7 +114,16 @@ NTSTATUS WINAPI RtlDestroyQueryDebugBuffer(IN PDEBUG_BUFFER iBuf)
 
 NTSTATUS WINAPI RtlQueryProcessDebugInformation(IN ULONG iProcessId, IN ULONG iDebugInfoMask, IN OUT PDEBUG_BUFFER iBuf) 
 {
-   NTSTATUS nts = STATUS_SUCCESS;
+    CLIENT_ID cid;
+    NTSTATUS status;
+    HANDLE process;
+
+    cid.UniqueProcess = ULongToHandle( iProcessId );
+    cid.UniqueThread = 0;
+
+    if (FAILED(status = NtOpenProcess( &process, PROCESS_QUERY_LIMITED_INFORMATION, NULL, &cid ))) return status;
+    NtClose( process );
+
    FIXME("(%d, %x, %p): stub\n", iProcessId, iDebugInfoMask, iBuf);
    iBuf->InfoClassMask = iDebugInfoMask;
    
@@ -139,5 +148,5 @@ NTSTATUS WINAPI RtlQueryProcessDebugInformation(IN ULONG iProcessId, IN ULONG iD
    }
    TRACE("returns:%p\n", iBuf);
    dump_DEBUG_BUFFER(iBuf);
-   return nts;
+   return status;
 }
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
index 897be4fcd12..28dd02fd118 100644
--- a/dlls/ntdll/tests/rtl.c
+++ b/dlls/ntdll/tests/rtl.c
@@ -132,6 +132,24 @@ static void InitFunctionPtrs(void)
     ok(strlen(src) == 15, "Source must be 16 bytes long!\n");
 }
 
+static void test_RtlQueryProcessDebugInformation(void)
+{
+    DEBUG_BUFFER *buffer;
+    NTSTATUS status;
+
+    buffer = RtlCreateQueryDebugBuffer( 0, 0 );
+    ok( buffer != NULL, "RtlCreateQueryDebugBuffer returned NULL" );
+
+    status = RtlQueryProcessDebugInformation( GetCurrentThreadId(), PDI_HEAPS | PDI_HEAP_BLOCKS, buffer );
+    ok( status == STATUS_INVALID_CID, "RtlQueryProcessDebugInformation returned %x\n", status );
+
+    status = RtlQueryProcessDebugInformation( GetCurrentProcessId(), PDI_HEAPS | PDI_HEAP_BLOCKS, buffer );
+    ok( !status, "RtlQueryProcessDebugInformation returned %x\n", status );
+
+    status = RtlDestroyQueryDebugBuffer( buffer );
+    ok( !status, "RtlDestroyQueryDebugBuffer returned %x\n", status );
+}
+
 #define COMP(str1,str2,cmplen,len) size = RtlCompareMemory(str1, str2, cmplen); \
   ok(size == len, "Expected %ld, got %ld\n", size, (SIZE_T)len)
 
@@ -3668,6 +3686,7 @@ START_TEST(rtl)
 {
     InitFunctionPtrs();
 
+    test_RtlQueryProcessDebugInformation();
     test_RtlCompareMemory();
     test_RtlCompareMemoryUlong();
     test_RtlMoveMemory();
-- 
2.29.2




More information about the wine-devel mailing list