Skip to content

Commit 4f61d2e

Browse files
authored
[KERNEL32] Fix use-after-free in GetStartupInfoA (reactos#8282)
- Set StartupInfo to point to the global BaseAnsiStartupInfo only after the local data has been freed.
1 parent 78ce856 commit 4f61d2e

File tree

1 file changed

+5
-3
lines changed
  • dll/win32/kernel32/client

1 file changed

+5
-3
lines changed

dll/win32/kernel32/client/proc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,7 @@ GetStartupInfoA(IN LPSTARTUPINFOA lpStartupInfo)
13971397
break;
13981398
}
13991399

1400-
/* Someone beat us to it, use their data instead */
1401-
StartupInfo = BaseAnsiStartupInfo;
1400+
/* Someone beat us to it, we will use their data instead */
14021401
Status = STATUS_SUCCESS;
14031402

14041403
/* We're going to free our own stuff, but not raise */
@@ -1409,6 +1408,9 @@ GetStartupInfoA(IN LPSTARTUPINFOA lpStartupInfo)
14091408
RtlFreeAnsiString(&ShellString);
14101409
}
14111410
RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo);
1411+
1412+
/* Get the cached information again: either still NULL or set by another thread */
1413+
StartupInfo = BaseAnsiStartupInfo;
14121414
}
14131415
else
14141416
{
@@ -1417,7 +1419,7 @@ GetStartupInfoA(IN LPSTARTUPINFOA lpStartupInfo)
14171419
}
14181420

14191421
/* Raise an error unless we got here due to the race condition */
1420-
if (!NT_SUCCESS(Status)) RtlRaiseStatus(Status);
1422+
if (!StartupInfo) RtlRaiseStatus(Status);
14211423
}
14221424

14231425
/* Now copy from the cached ANSI version */

0 commit comments

Comments
 (0)