- Fix freed memory usage in SeLocateProcessImageName, spotted by Jan Roeloffzen.
authorAleksey Bragin <aleksey@reactos.org>
Tue, 24 Feb 2009 11:06:13 +0000 (11:06 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Tue, 24 Feb 2009 11:06:13 +0000 (11:06 +0000)
- Use a correct structure member in SeAuditProcessCreationInfo (but it's still the same pointer).
- Rewrite bottom part of the function to better match ReactOS coding style.
See issue #4087 for more details.

svn path=/trunk/; revision=39736

reactos/ntoskrnl/se/audit.c

index 00e3ff7..9bc3d83 100644 (file)
@@ -139,7 +139,7 @@ SeLocateProcessImageName(IN PEPROCESS Process,
         {
             /* Set it */
             if (InterlockedCompareExchangePointer(&Process->
-                                                  SeAuditProcessCreationInfo,
+                                                  SeAuditProcessCreationInfo.ImageFileName,
                                                   AuditName,
                                                   NULL))
             {
@@ -153,29 +153,26 @@ SeLocateProcessImageName(IN PEPROCESS Process,
         if (!NT_SUCCESS(Status)) return Status;
     }
 
+    /* Get audit info again, now we have it for sure */
+    AuditName = Process->SeAuditProcessCreationInfo.ImageFileName;
+
     /* Allocate the output string */
     ImageName = ExAllocatePoolWithTag(NonPagedPool,
                                       AuditName->Name.MaximumLength +
                                       sizeof(UNICODE_STRING),
                                       TAG_SEPA);
-    if (ImageName)
-    {
-        /* Make a copy of it */
-        RtlCopyMemory(ImageName,
-                      &AuditName->Name,
-                      AuditName->Name.MaximumLength + sizeof(UNICODE_STRING));
+    if (!ImageName) return STATUS_NO_MEMORY;
 
-        /* Fix up the buffer */
-        ImageName->Buffer = (PWSTR)(ImageName + 1);
+    /* Make a copy of it */
+    RtlCopyMemory(ImageName,
+                  &AuditName->Name,
+                  AuditName->Name.MaximumLength + sizeof(UNICODE_STRING));
 
-        /* Return it */
-        *ProcessImageName = ImageName;
-    }
-    else
-    {
-        /* Otherwise, fail */
-        Status = STATUS_NO_MEMORY;
-    }
+    /* Fix up the buffer */
+    ImageName->Buffer = (PWSTR)(ImageName + 1);
+
+    /* Return it */
+    *ProcessImageName = ImageName;
 
     /* Return status */
     return Status;