From adf80f6d5989b03093768c316692adcd0bfaa787 Mon Sep 17 00:00:00 2001 From: Kamil Hornicek Date: Fri, 17 Oct 2014 16:39:54 +0000 Subject: [PATCH] [CMD] - prevent a buffer underrun (fixes stray quotes being appended on autocomplete in some cases) - check if the input string is not empty (fixes first file in directory getting skipped on autocomplete) - fix some typos CORE-8623 svn path=/trunk/; revision=64787 --- reactos/base/shell/cmd/filecomp.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/reactos/base/shell/cmd/filecomp.c b/reactos/base/shell/cmd/filecomp.c index f5b6ac67f23..adacf9092fb 100644 --- a/reactos/base/shell/cmd/filecomp.c +++ b/reactos/base/shell/cmd/filecomp.c @@ -556,7 +556,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) /* Used to find and assemble the string that is returned */ TCHAR szBaseWord[MAX_PATH]; TCHAR szPrefix[MAX_PATH]; - TCHAR szOrginal[MAX_PATH]; + TCHAR szOriginal[MAX_PATH]; TCHAR szSearchPath[MAX_PATH]; /* Save the strings used last time, so if they hit tab again */ static TCHAR LastReturned[MAX_PATH]; @@ -586,9 +586,9 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) if (!_tcsnicmp (line, _T("rd "), 3) || !_tcsnicmp (line, _T("cd "), 3)) ShowAll = FALSE; - /* Copy the string, str can be edited and orginal should not be */ + /* Copy the string, str can be edited and original should not be */ _tcscpy(str,strIN); - _tcscpy(szOrginal,strIN); + _tcscpy(szOriginal,strIN); /* Look to see if the cusor is not at the end of the string */ if ((cusor + 1) < _tcslen(str)) @@ -656,8 +656,8 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) hFile = FindFirstFile (szSearchPath, &file); if (hFile == INVALID_HANDLE_VALUE) { - /* Assemble the orginal string and return */ - _tcscpy(strOut,szOrginal); + /* Assemble the original string and return */ + _tcscpy(strOut,szOriginal); return; } @@ -685,8 +685,8 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) { /* Don't leak old buffer */ cmd_free(oldFileList); - /* Assemble the orginal string and return */ - _tcscpy(strOut,szOrginal); + /* Assemble the original string and return */ + _tcscpy(strOut,szOriginal); FindClose(hFile); ConOutFormatMessage (GetLastError()); return; @@ -698,11 +698,10 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) FindClose(hFile); - /* Check the size of the list to see if we - found any matches */ + /* Check the size of the list to see if we found any matches */ if (FileListSize == 0) { - _tcscpy(strOut,szOrginal); + _tcscpy(strOut,szOriginal); if (FileList != NULL) cmd_free(FileList); return; @@ -712,7 +711,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) qsort(FileList,FileListSize,sizeof(FileName), compare); /* Find the next/previous */ - if (!_tcscmp(szOrginal,LastReturned)) + if (_tcslen(szOriginal) && !_tcscmp(szOriginal,LastReturned)) { if (bNext) { @@ -734,8 +733,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) Sel = 0; } - /* nothing found that matched last time - so return the first thing in the list */ + /* nothing found that matched last time so return the first thing in the list */ strOut[0] = _T('\0'); /* Special character in the name */ @@ -792,7 +790,7 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor) } } - if (szPrefix[_tcslen(szPrefix) - 1] == _T('\"') || NeededQuote) + if (NeededQuote || (_tcslen(szPrefix) && szPrefix[_tcslen(szPrefix) - 1] == _T('\"'))) _tcscat(strOut,_T("\"")); _tcscpy(LastReturned,strOut);