Fix: Stop the client file search from overflowing its path buffers
SearchFilesRecursive built "%s\*.*" and "%s\%s" with wsprintf into char[MAX_PATH] buffers and never checked the lengths. The recursion allows 32 levels, so a search from a drive root accumulates paths well past 260 characters and writes off the end of the stack frame. Debug builds raise Run-Time Check Failure #2 and the dialog blocks the search thread; release builds corrupt the stack silently. Check the length before each build and skip the entry when the full path does not fit, so neither the name nor the recursion below it is recorded. The root directory is checked once at function entry, which also stops an over-long root from being enumerated at all. Apply the same guard to the directory listing paths in both file managers, and bound the search pattern built from the incoming keyword. Zero-initialize the buffers filled by ExpandEnvironmentStringsA so a failed expansion is treated as an empty path instead of reading uninitialized stack. Verified against the debug client with a full C:\ scan (10,000 results, finished, no dialog) and a repeated deep search afterwards. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
abe7e99a77
commit
8f718d9b39
2 files changed
+32
-2
No files matched your search
@@ -573,6 +573,11 @@ UINT CFileManager::SendFilesList(TCHAR* lpszDirectory)
|
||||
else
|
||||
lpszSlash = _T("");
|
||||
TCHAR str_last[] = { _T('%'),_T('s'),_T('%'),_T('s'),_T('*'),_T('.'),_T('*'),_T('\0') };
|
||||
// wsprintf 不做边界检查:目录 + "\*.*" + NUL 装不下就按空目录回,别写穿 strPath。
|
||||
if ((int)(_tcslen(lpszDirectory) + _tcslen(lpszSlash)) + 4 > MAX_PATH) {
|
||||
BYTE bToken = TOKEN_FILE_LIST;
|
||||
return Send(&bToken, 1);
|
||||
}
|
||||
wsprintf(strPath, str_last, lpszDirectory, lpszSlash);
|
||||
hFile = FindFirstFile(strPath, &FindFileData);
|
||||
|
||||
|
||||
Reference in new issue
Block a user