From c8a180611e0ae4203ce880085b214882e58cf253 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Mon, 8 Aug 2005 18:59:56 +0000 Subject: [PATCH] fixing bug 690 by Brandon Turner. note ms only allown start "notepad" or "note"pad not notep"ad or notepad" but we do that, for we think it is a bug in ms cmd that only allowing " at start of a file name to start the apps. svn path=/trunk/; revision=17218 --- reactos/subsys/system/cmd/cmd.c | 55 +++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/reactos/subsys/system/cmd/cmd.c b/reactos/subsys/system/cmd/cmd.c index 05e6ec7cfbb..a71cfd68733 100644 --- a/reactos/subsys/system/cmd/cmd.c +++ b/reactos/subsys/system/cmd/cmd.c @@ -287,14 +287,18 @@ static BOOL RunFile(LPTSTR filename) /* * This command (in first) was not found in the command table * - * first - first word on command line - * rest - rest of command line + * Full - whole command line + * First - first word on command line + * Rest - rest of command line */ static VOID -Execute (LPTSTR full, LPTSTR first, LPTSTR rest) +Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest) { TCHAR szFullName[MAX_PATH]; + TCHAR first[MAX_PATH]; + TCHAR rest[MAX_PATH]; + TCHAR full[MAX_PATH]; #ifndef __REACTOS__ TCHAR szWindowTitle[MAX_PATH]; #endif @@ -304,6 +308,51 @@ Execute (LPTSTR full, LPTSTR first, LPTSTR rest) DebugPrintf (_T("Execute: \'%s\' \'%s\'\n"), first, rest); #endif + /* Though it was already parsed once, we have a different set of rules + for parsing before we pass to CreateProccess */ + if(!_tcschr(Full,_T('\"'))) + { + _tcscpy(first,First); + _tcscpy(rest,Rest); + _tcscpy(full,Full); + } + else + { + INT i = 0; + BOOL bInside = FALSE; + rest[0] = _T('\0'); + full[0] = _T('\0'); + first[0] = _T('\0'); + _tcscpy(first,Full); + /* find the end of the command and start of the args */ + for(i = 0; i < _tcslen(first); i++) + { + if(!_tcsncmp(&first[i], _T("\""), 1)) + bInside = !bInside; + if(!_tcsncmp(&first[i], _T(" "), 1) && !bInside) + { + _tcscpy(rest,&first[i]); + first[i] = _T('\0'); + break; + } + + } + i = 0; + /* remove any slashes */ + while(i < _tcslen(first)) + { + if(!_tcsncmp (&first[i], _T("\""), 1)) + memcpy(&first[i],&first[i + 1], _tcslen(&first[i])); + else + i++; + } + /* Drop quotes around it just in case there is a space */ + _tcscpy(full,_T("\"")); + _tcscat(full,first); + _tcscat(full,_T("\" ")); + _tcscat(full,rest); + } + /* check for a drive change */ if ((_istalpha (first[0])) && (!_tcscmp (first + 1, _T(":")))) {