From 65a58c440e177edec2777025d9d45c3229897f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 18 May 2014 23:45:43 +0000 Subject: [PATCH] [NTVDM] Correctly NULL-terminate the command-lines when needed (and avoid buffer overruns). svn path=/trunk/; revision=63365 --- reactos/subsystems/ntvdm/dos/dem.c | 4 ++-- reactos/subsystems/ntvdm/dos/dos32krnl/dos.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/reactos/subsystems/ntvdm/dos/dem.c b/reactos/subsystems/ntvdm/dos/dem.c index f0b251d2e03..a0b1a5baac6 100644 --- a/reactos/subsystems/ntvdm/dos/dem.c +++ b/reactos/subsystems/ntvdm/dos/dem.c @@ -119,8 +119,8 @@ static VOID WINAPI DosCmdInterpreterBop(LPWORD Stack) STARTUPINFOA StartupInfo; PROCESS_INFORMATION ProcessInformation; - /* NULL-terminate the command by removing the return carriage character */ - while (*CmdPtr != '\r') CmdPtr++; + /* NULL-terminate the command line by removing the return carriage character */ + while (*CmdPtr && *CmdPtr != '\r') CmdPtr++; *CmdPtr = '\0'; DPRINT1("CMD Run Command '%s'\n", Command); diff --git a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c index 6925c268ce8..353fa6d3c22 100644 --- a/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c +++ b/reactos/subsystems/ntvdm/dos/dos32krnl/dos.c @@ -926,6 +926,10 @@ DWORD DosLoadExecutable(IN DOS_EXEC_TYPE LoadType, return ERROR_NOT_SUPPORTED; } + /* NULL-terminate the command line by removing the return carriage character */ + while (*CommandLine && *CommandLine != '\r') CommandLine++; + *(LPSTR)CommandLine = '\0'; + /* Open a handle to the executable */ FileHandle = CreateFileA(ExecutablePath, GENERIC_READ,