[SMSS] Fix the displayed subsystem name in the failure path of SmpSbCreateSession().

The SubSystemNames array didn't correlate with the possible values of
SubSystemType (e.g. index 4 was "Posix" whereas Posix is type 7; Posix
and OS/2 entries were inverted; Windows CUI subsystem (type 3) was
mapped to "Posix"), and the array dereferencing was out of bounds if the
SubSystemType of the image happened to be larger than 8.

I know (strings extraction from debug build of Windows' SMSS.EXE) that
they use that same old'n'broken array. Perhaps a leftover from very old
times (NT 3.1 betas) where the PE format was under work and the
subsystem numbers didn't have their definitive values... (This has
already happened with the NT PDK v1.196 from September 1991.)
This commit is contained in:
Hermès Bélusca-Maïto 2022-10-23 19:59:08 +02:00
parent bcbfcd2278
commit b076800dd8
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -15,14 +15,19 @@
/* GLOBALS ********************************************************************/
PCHAR SmpSubSystemNames[] =
#if DBG
const PCSTR SmpSubSystemNames[] =
{
"Unknown",
"Native",
"Windows",
"Posix",
"OS/2"
"Windows GUI",
"Windows CUI",
NULL,
"OS/2 CUI"
NULL,
"Posix CUI"
};
#endif
/* FUNCTIONS ******************************************************************/
@ -35,6 +40,7 @@ SmpSbCreateSession(IN PVOID Reserved,
IN PCLIENT_ID DbgClientId)
{
NTSTATUS Status;
ULONG SubSystemType = ProcessInformation->ImageInformation.SubSystemType;
PSMP_SUBSYSTEM KnownSubsys;
SB_API_MSG SbApiMsg;
ULONG SessionId;
@ -65,9 +71,7 @@ SmpSbCreateSession(IN PVOID Reserved,
}
/* Find the subsystem we have for this initial process */
KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId,
ProcessInformation->
ImageInformation.SubSystemType);
KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId, SubSystemType);
if (KnownSubsys)
{
/* Duplicate the process handle into the message */
@ -142,11 +146,22 @@ SmpSbCreateSession(IN PVOID Reserved,
}
/* If we don't yet have a subsystem, only native images can be launched */
if (ProcessInformation->ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
if (SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
{
/* Fail */
DPRINT1("SMSS: %s SubSystem has not been started.\n",
SmpSubSystemNames[ProcessInformation->ImageInformation.SubSystemType]);
#if DBG
PCSTR SubSysName = NULL;
CHAR SubSysTypeName[sizeof("Type 0x")+8];
if (SubSystemType < RTL_NUMBER_OF(SmpSubSystemNames))
SubSysName = SmpSubSystemNames[SubSystemType];
if (!SubSysName)
{
SubSysName = SubSysTypeName;
sprintf(SubSysTypeName, "Type 0x%08x", SubSystemType);
}
DPRINT1("SMSS: %s SubSystem not found (either not started or destroyed).\n", SubSysName);
#endif
Status = STATUS_UNSUCCESSFUL;
NtClose(ProcessInformation->ProcessHandle);
NtClose(ProcessInformation->ThreadHandle);