When DOS program executes another DOS program, command line is now

passed correctly. If DOS command line is too long, command line is now
truncated instead of letting it trash memory.
This commit is contained in:
Jukka Heinonen 2002-05-01 18:04:11 +00:00 committed by Alexandre Julliard
parent b7b75a86ec
commit 7ec04452a1
1 changed files with 28 additions and 16 deletions

View File

@ -112,21 +112,28 @@ static void MZ_CreatePSP( LPVOID lpPSP, WORD env, WORD par )
/* FIXME: more PSP stuff */ /* FIXME: more PSP stuff */
} }
static void MZ_FillPSP( LPVOID lpPSP, LPCSTR cmdline ) static void MZ_FillPSP( LPVOID lpPSP, LPBYTE cmdline, int length )
{ {
PDB16 *psp = lpPSP; PDB16 *psp = lpPSP;
const char*cmd=cmdline?strchr(cmdline,' '):NULL;
/* copy parameters */ while(length > 0 && *cmdline != ' ') {
if (cmd) { length--;
#if 0 cmdline++;
/* command.com doesn't do this */ }
while (*cmd == ' ') cmd++;
#endif /* command.com does not skip over multiple spaces */
psp->cmdLine[0]=strlen(cmd);
strcpy(psp->cmdLine+1,cmd); if(length > 126) {
psp->cmdLine[psp->cmdLine[0]+1]='\r'; ERR("Command line truncated! (length %d > maximum length 126)\n",
} else psp->cmdLine[1]='\r'; length);
length = 126;
}
psp->cmdLine[0] = length;
if(length > 0)
memmove(psp->cmdLine+1, cmdline, length);
psp->cmdLine[length+1] = '\r';
/* FIXME: more PSP stuff */ /* FIXME: more PSP stuff */
} }
@ -356,7 +363,11 @@ BOOL WINAPI MZ_Exec( CONTEXT86 *context, LPCSTR filename, BYTE func, LPVOID para
* let's work on the new values now */ * let's work on the new values now */
LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4); LPBYTE psp_start = (LPBYTE)((DWORD)DOSVM_psp << 4);
ExecBlock *blk = (ExecBlock *)paramblk; ExecBlock *blk = (ExecBlock *)paramblk;
MZ_FillPSP(psp_start, DOSMEM_MapRealToLinear(blk->cmdline)); LPBYTE cmdline = DOSMEM_MapRealToLinear(blk->cmdline);
/* First character contains the length of the command line. */
MZ_FillPSP(psp_start, cmdline + 1, cmdline[0]);
/* the lame MS-DOS engineers decided that the return address should be in int22 */ /* the lame MS-DOS engineers decided that the return address should be in int22 */
DOSVM_SetRMHandler(0x22, (FARPROC16)MAKESEGPTR(context->SegCs, LOWORD(context->Eip))); DOSVM_SetRMHandler(0x22, (FARPROC16)MAKESEGPTR(context->SegCs, LOWORD(context->Eip)));
if (func) { if (func) {
@ -462,8 +473,9 @@ static void MZ_Launch(void)
{ {
TDB *pTask = TASK_GetCurrent(); TDB *pTask = TASK_GetCurrent();
BYTE *psp_start = PTR_REAL_TO_LIN( DOSVM_psp, 0 ); BYTE *psp_start = PTR_REAL_TO_LIN( DOSVM_psp, 0 );
LPSTR cmdline = GetCommandLineA();
MZ_FillPSP(psp_start, GetCommandLineA()); MZ_FillPSP(psp_start, cmdline, cmdline ? strlen(cmdline) : 0);
pTask->flags |= TDBF_WINOLDAP; pTask->flags |= TDBF_WINOLDAP;
_LeaveWin16Lock(); _LeaveWin16Lock();