From b75ee7fd147eb58288965481160b88e9c6d3cf93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 26 Jan 2013 21:23:10 +0000 Subject: [PATCH] [CSRSRV] - Zero-out some allocated memory. - During my investigations preceding the implementation of AttachConsole (r58166), I wanted (in a first attempt; finally I've found a better way to achieve what I wanted to do) to retrieve the CSR_PROCESS structure of the parent of a given process. I've found the 'Parent' member in the CSR_PROCESS structure, however this member was always initialized to NULL when new processes were created via CsrCreateProcess (and via the call to CsrInsertProcess). After looking at some informating here (http://svn.reactos.org/svn/reactos/trunk/reactos/include/subsys/csr/server.h?r1=17363&r2=17362&pathrev=17363) and there (http://forum.sysinternals.com/csrwalker-processes-detection-from-user-mode_topic15457.html), I became convinced that the 'Parent' member was unexistent starting from Windows Server 2003. Also, after much more investigation, I've found that the CsrInsertProcess function was called with only two parameters starting from Windows Server 2003 (and still continues in Windows 7), the always-NULL paramater being removed. Therefore, I remove that unneeded parameter from CsrInsertProcess and the corresponding 'Parent' member from CSR_PROCESS. svn path=/branches/ros-csrss/; revision=58232 --- include/reactos/subsys/csr/csrsrv.h | 1 - subsystems/win32/csrsrv/api.c | 2 +- subsystems/win32/csrsrv/include/api.h | 3 +-- subsystems/win32/csrsrv/procsup.c | 19 ++++++------------- subsystems/win32/csrsrv/server.c | 10 +++++----- subsystems/win32/csrsrv/session.c | 4 ++-- subsystems/win32/csrsrv/wait.c | 2 +- 7 files changed, 16 insertions(+), 25 deletions(-) diff --git a/include/reactos/subsys/csr/csrsrv.h b/include/reactos/subsys/csr/csrsrv.h index 19e9d10cd6c..0815360641b 100644 --- a/include/reactos/subsys/csr/csrsrv.h +++ b/include/reactos/subsys/csr/csrsrv.h @@ -39,7 +39,6 @@ typedef struct _CSR_PROCESS CLIENT_ID ClientId; LIST_ENTRY ListLink; LIST_ENTRY ThreadList; - struct _CSR_PROCESS *Parent; PCSR_NT_SESSION NtSession; ULONG ExpectedVersion; HANDLE ClientPort; diff --git a/subsystems/win32/csrsrv/api.c b/subsystems/win32/csrsrv/api.c index b9a330742b0..72b802c1b12 100644 --- a/subsystems/win32/csrsrv/api.c +++ b/subsystems/win32/csrsrv/api.c @@ -1171,7 +1171,7 @@ CsrCaptureArguments(IN PCSR_THREAD CsrThread, } _SEH2_END; /* We validated the incoming buffer, now allocate the remote one */ - RemoteCaptureBuffer = RtlAllocateHeap(CsrHeap, 0, Length); + RemoteCaptureBuffer = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, Length); if (!RemoteCaptureBuffer) { /* We're out of memory */ diff --git a/subsystems/win32/csrsrv/include/api.h b/subsystems/win32/csrsrv/include/api.h index 7124dbc2f7b..a2406189158 100644 --- a/subsystems/win32/csrsrv/include/api.h +++ b/subsystems/win32/csrsrv/include/api.h @@ -119,8 +119,7 @@ CsrRemoveProcess(IN PCSR_PROCESS CsrProcess); VOID NTAPI -CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL, - IN PCSR_PROCESS CurrentProcess OPTIONAL, +CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, IN PCSR_PROCESS CsrProcess); NTSTATUS diff --git a/subsystems/win32/csrsrv/procsup.c b/subsystems/win32/csrsrv/procsup.c index 72b97d8596a..fe96ddb6942 100644 --- a/subsystems/win32/csrsrv/procsup.c +++ b/subsystems/win32/csrsrv/procsup.c @@ -451,11 +451,8 @@ CsrRemoveProcess(IN PCSR_PROCESS CsrProcess) * The CsrInsertProcess routine inserts a CSR Process into the Process List * and notifies Server DLLs of the creation of a new CSR Process. * - * @param Parent - * Optional pointer to the CSR Process creating this CSR Process. - * - * @param CurrentProcess - * Optional pointer to the current CSR Process. + * @param ParentProcess + * Optional pointer to the Parent Process creating this CSR Process. * * @param CsrProcess * Pointer to the CSR Process which is to be inserted. @@ -467,17 +464,13 @@ CsrRemoveProcess(IN PCSR_PROCESS CsrProcess) *--*/ VOID NTAPI -CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL, // ParentProcess - IN PCSR_PROCESS CurrentProcess OPTIONAL, // CallingProcess - IN PCSR_PROCESS CsrProcess) // Process +CsrInsertProcess(IN PCSR_PROCESS ParentProcess OPTIONAL, + IN PCSR_PROCESS CsrProcess) { PCSR_SERVER_DLL ServerDll; ULONG i; ASSERT(ProcessStructureListLocked()); - /* Set the parent */ - CsrProcess->Parent = Parent; - /* Insert it into the Root List */ InsertTailList(&CsrRootProcess->ListLink, &CsrProcess->ListLink); @@ -490,7 +483,7 @@ CsrInsertProcess(IN PCSR_PROCESS Parent OPTIONAL, // ParentProcess /* Make sure it's valid and that it has callback */ if (ServerDll && ServerDll->NewProcessCallback) { - ServerDll->NewProcessCallback(CurrentProcess, CsrProcess); + ServerDll->NewProcessCallback(ParentProcess, CsrProcess); } } } @@ -706,7 +699,7 @@ CsrCreateProcess(IN HANDLE hProcess, CsrSetBackgroundPriority(CsrProcess); /* Insert the Process */ - CsrInsertProcess(NULL, CurrentProcess, CsrProcess); + CsrInsertProcess(CurrentProcess, CsrProcess); /* Release lock and return */ CsrReleaseProcessLock(); diff --git a/subsystems/win32/csrsrv/server.c b/subsystems/win32/csrsrv/server.c index c20ec56e091..a858a5e3f3f 100644 --- a/subsystems/win32/csrsrv/server.c +++ b/subsystems/win32/csrsrv/server.c @@ -43,11 +43,11 @@ PCHAR CsrServerApiNameTable[CsrpMaxApiNumber] = }; PCSR_SERVER_DLL CsrLoadedServerDll[CSR_SERVER_DLL_MAX]; -PVOID CsrSrvSharedSectionHeap; -PVOID CsrSrvSharedSectionBase; -PVOID *CsrSrvSharedStaticServerData; -ULONG CsrSrvSharedSectionSize; -HANDLE CsrSrvSharedSection; +PVOID CsrSrvSharedSectionHeap = NULL; +PVOID CsrSrvSharedSectionBase = NULL; +PVOID *CsrSrvSharedStaticServerData = NULL; +ULONG CsrSrvSharedSectionSize = 0; +HANDLE CsrSrvSharedSection = NULL; /* PRIVATE FUNCTIONS **********************************************************/ diff --git a/subsystems/win32/csrsrv/session.c b/subsystems/win32/csrsrv/session.c index 97fd95e2240..8a2039b477b 100644 --- a/subsystems/win32/csrsrv/session.c +++ b/subsystems/win32/csrsrv/session.c @@ -84,7 +84,7 @@ CsrAllocateNtSession(IN ULONG SessionId) PCSR_NT_SESSION NtSession; /* Allocate an NT Session Object */ - NtSession = RtlAllocateHeap(CsrHeap, 0, sizeof(CSR_NT_SESSION)); + NtSession = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_NT_SESSION)); if (NtSession) { /* Setup the Session Object */ @@ -331,7 +331,7 @@ CsrSbCreateSession(IN PSB_API_MSG ApiMessage) } /* Insert the Process */ - CsrInsertProcess(NULL, NULL, CsrProcess); + CsrInsertProcess(NULL, CsrProcess); /* Activate the Thread */ ApiMessage->ReturnValue = NtResumeThread(hThread, NULL); diff --git a/subsystems/win32/csrsrv/wait.c b/subsystems/win32/csrsrv/wait.c index da33727253d..73518703fb7 100644 --- a/subsystems/win32/csrsrv/wait.c +++ b/subsystems/win32/csrsrv/wait.c @@ -62,7 +62,7 @@ CsrInitializeWait(IN CSR_WAIT_FUNCTION WaitFunction, WaitApiMessage->Header.u1.s1.TotalLength; /* Allocate the Wait Block */ - WaitBlock = RtlAllocateHeap(CsrHeap, 0, Size); + WaitBlock = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, Size); if (!WaitBlock) { /* Fail */ -- 2.17.1