- Fix logic bugs in LpcRequestPort (which is not the same as NtRequestPort as someone...
authorAleksey Bragin <aleksey@reactos.org>
Wed, 23 Apr 2008 16:40:08 +0000 (16:40 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Wed, 23 Apr 2008 16:40:08 +0000 (16:40 +0000)
svn path=/trunk/; revision=33128

reactos/ntoskrnl/lpc/close.c
reactos/ntoskrnl/lpc/connect.c
reactos/ntoskrnl/lpc/send.c

index 89ec7d3..d142d0f 100644 (file)
@@ -374,7 +374,7 @@ LpcpDeletePort(IN PVOID ObjectBody)
         }
 
         /* Dereference the mapping process */
-        //ObDereferenceObject(Port->MappingProcess);
+        ObDereferenceObject(Port->MappingProcess);
         Port->MappingProcess = NULL;
     }
 
index 1d71c38..38d22c9 100644 (file)
@@ -299,7 +299,7 @@ NtSecureConnectPort(OUT PHANDLE PortHandle,
 
         /* Reference and remember the process */
         ClientPort->MappingProcess = PsGetCurrentProcess();
-        //ObReferenceObject(ClientPort->MappingProcess);
+        ObReferenceObject(ClientPort->MappingProcess);
     }
     else
     {
index e1d6cbd..f0bbaaf 100644 (file)
@@ -198,28 +198,41 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
     if (Thread->LpcExitThreadCalled) return STATUS_THREAD_IS_TERMINATING;
 
     /* Check if this is an LPC Request */
-    if (LpcpGetMessageType(LpcRequest) == LPC_REQUEST)
-    {
-        /* Then it's a callback */
-        Callback = TRUE;
-    }
-    else
-    {
-        /* This is a kernel-mode message without a callback */
-        LpcRequest->u2.s2.Type |= LPC_REQUEST;
-        Callback = FALSE;
-    }
-
-    /* Get the message type */
-    MessageType = LpcRequest->u2.s2.Type;
-
-    /* Validate the length */
-    if (((ULONG)LpcRequest->u1.s1.DataLength + sizeof(PORT_MESSAGE)) >
-         (ULONG)LpcRequest->u1.s1.TotalLength)
+    MessageType = LpcpGetMessageType(LpcRequest);
+    switch (MessageType)
     {
-        /* Fail */
-        return STATUS_INVALID_PARAMETER;
+        /* No type */
+        case 0:
+            
+            /* Assume LPC request */
+            MessageType = LPC_REQUEST;
+            break;
+        
+        /* LPC request callback */
+        case LPC_REQUEST:
+            
+            /* This is a callback */
+            Callback = TRUE;
+            break;
+        
+        /* Anything else */
+        case LPC_CLIENT_DIED:
+        case LPC_PORT_CLOSED:
+        case LPC_EXCEPTION:
+        case LPC_DEBUG_EVENT:
+        case LPC_ERROR_EVENT:
+            
+            /* Nothing to do */
+            break;
+            
+        default:
+            
+            /* Invalid message type */
+            return STATUS_INVALID_PARAMETER;
     }
+    
+    /* Set the request type */
+    LpcRequest->u2.s2.Type = MessageType;
 
     /* Validate the message length */
     if (((ULONG)LpcRequest->u1.s1.TotalLength > Port->MaxMessageLength) ||
@@ -250,7 +263,7 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
         LpcpMoveMessage(&Message->Request,
                         LpcRequest,
                         LpcRequest + 1,
-                        MessageType,
+                        0,
                         &Thread->Cid);
 
         /* Acquire the LPC lock */
@@ -383,19 +396,21 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
                             (&Message->Request) + 1,
                             0,
                             NULL);
-
-            /* Check if this is an LPC request with data information */
-            if ((LpcpGetMessageType(&Message->Request) == LPC_REQUEST) &&
-                (Message->Request.u2.s2.DataInfoOffset))
+            
+            /* Acquire the lock */
+            KeAcquireGuardedMutex(&LpcpLock);
+            
+            /* Check if we replied to a thread */
+            if (Message->RepliedToThread)
             {
-                /* Save the data information */
-                LpcpSaveDataInfoMessage(Port, Message, 0);
-            }
-            else
-            {
-                /* Otherwise, just free it */
-                LpcpFreeToPortZone(Message, 0);
+                /* Dereference */
+                ObDereferenceObject(Message->RepliedToThread);
+                Message->RepliedToThread = NULL;
             }
+
+
+            /* Free the message */
+            LpcpFreeToPortZone(Message, 3);
         }
         else
         {
@@ -415,6 +430,7 @@ LpcRequestWaitReplyPort(IN PVOID PortObject,
              Port,
              Status);
 
+    /* Dereference the connection port */
     if (ConnectionPort) ObDereferenceObject(ConnectionPort);
     return Status;
 }