From df1d5b70324acf3d415fdc9a0d42c92d04d3f14d Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Sat, 31 Jan 2004 21:01:53 +0000 Subject: [PATCH] - don't sort registry hives - fix for memory corruption problem svn path=/trunk/; revision=7945 --- .../subsys/system/explorer/doxy-footer.html | 2 +- .../subsys/system/explorer/shell/entries.cpp | 44 +++++++++++-------- .../subsys/system/explorer/shell/entries.h | 1 + .../system/explorer/shell/filechild.cpp | 10 ++--- .../subsys/system/explorer/shell/ntobjfs.cpp | 22 +++++----- .../subsys/system/explorer/shell/regfs.cpp | 7 ++- 6 files changed, 49 insertions(+), 37 deletions(-) diff --git a/reactos/subsys/system/explorer/doxy-footer.html b/reactos/subsys/system/explorer/doxy-footer.html index d2ff7f41d11..5d45c00815d 100644 --- a/reactos/subsys/system/explorer/doxy-footer.html +++ b/reactos/subsys/system/explorer/doxy-footer.html @@ -3,7 +3,7 @@
ROS Explorer Source Code Documentation -
generated on 25.01.2004 by +
generated on 31.01.2004 by
doxygen
diff --git a/reactos/subsys/system/explorer/shell/entries.cpp b/reactos/subsys/system/explorer/shell/entries.cpp index 6f69794cedb..5540eb677a4 100644 --- a/reactos/subsys/system/explorer/shell/entries.cpp +++ b/reactos/subsys/system/explorer/shell/entries.cpp @@ -167,6 +167,11 @@ static int compareType(const WIN32_FIND_DATA* fd1, const WIN32_FIND_DATA* fd2) } +static int compareNothing(const void* arg1, const void* arg2) +{ + return -1; +} + static int compareName(const void* arg1, const void* arg2) { const WIN32_FIND_DATA* fd1 = &(*(Entry**)arg1)->_data; @@ -247,6 +252,7 @@ static int compareDate(const void* arg1, const void* arg2) static int (*sortFunctions[])(const void* arg1, const void* arg2) = { + compareNothing, // SORT_NONE compareName, // SORT_NAME compareExt, // SORT_EXT compareSize, // SORT_SIZE @@ -256,30 +262,32 @@ static int (*sortFunctions[])(const void* arg1, const void* arg2) = { void Entry::sort_directory(SORT_ORDER sortOrder) { - Entry* entry = _down; - Entry** array, **p; - int len; + if (sortOrder != SORT_NONE) { + Entry* entry = _down; + Entry** array, **p; + int len; - len = 0; - for(entry=_down; entry; entry=entry->_next) - ++len; - - if (len) { - array = (Entry**) alloca(len*sizeof(Entry*)); - - p = array; + len = 0; for(entry=_down; entry; entry=entry->_next) - *p++ = entry; + ++len; - // call qsort with the appropriate compare function - qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]); + if (len) { + array = (Entry**) alloca(len*sizeof(Entry*)); - _down = array[0]; + p = array; + for(entry=_down; entry; entry=entry->_next) + *p++ = entry; - for(p=array; --len; p++) - p[0]->_next = p[1]; + // call qsort with the appropriate compare function + qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]); - (*p)->_next = 0; + _down = array[0]; + + for(p=array; --len; p++) + (*p)->_next = p[1]; + + (*p)->_next = 0; + } } } diff --git a/reactos/subsys/system/explorer/shell/entries.h b/reactos/subsys/system/explorer/shell/entries.h index aeab336de54..4f5564f1f42 100644 --- a/reactos/subsys/system/explorer/shell/entries.h +++ b/reactos/subsys/system/explorer/shell/entries.h @@ -37,6 +37,7 @@ enum ENTRY_TYPE { }; enum SORT_ORDER { + SORT_NONE, SORT_NAME, SORT_EXT, SORT_SIZE, diff --git a/reactos/subsys/system/explorer/shell/filechild.cpp b/reactos/subsys/system/explorer/shell/filechild.cpp index fc2b17355e8..86ce1b59799 100644 --- a/reactos/subsys/system/explorer/shell/filechild.cpp +++ b/reactos/subsys/system/explorer/shell/filechild.cpp @@ -100,7 +100,7 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) const ShellChildWndInfo& shell_info = static_cast(info); _root._entry = new ShellDirectory(Desktop(), DesktopFolderPath(), hwnd); - entry = _root._entry->read_tree((LPCTSTR)&*shell_info._shell_path, SORT_NAME/*_sortOrder*/); + entry = _root._entry->read_tree((LPCTSTR)&*shell_info._shell_path, SORT_NAME); } else #ifdef __WINE__ @@ -115,7 +115,7 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) lstrcpy(_root._fs, TEXT("unixfs")); lstrcpy(_root._path, TEXT("/")); _root._entry = new UnixDirectory(_root._path); - entry = _root._entry->read_tree(info._path, SORT_NAME/*_sortOrder*/); + entry = _root._entry->read_tree(info._path, SORT_NAME); } else #endif @@ -129,7 +129,7 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) lstrcpy(_root._fs, TEXT("NTOBJ")); lstrcpy(_root._path, drv); _root._entry = new NtObjDirectory(_root._path); - entry = _root._entry->read_tree(info._path, SORT_NAME/*_sortOrder*/); + entry = _root._entry->read_tree(info._path, SORT_NAME); } else if (info._etype == ET_REGISTRY) { @@ -141,7 +141,7 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) lstrcpy(_root._fs, TEXT("Registry")); lstrcpy(_root._path, drv); _root._entry = new RegistryRoot(); - entry = _root._entry->read_tree(info._path, SORT_NAME/*_sortOrder*/); + entry = _root._entry->read_tree(info._path, SORT_NONE); } else //if (info._etype == ET_WINDOWS) { @@ -152,7 +152,7 @@ FileChildWindow::FileChildWindow(HWND hwnd, const FileChildWndInfo& info) GetVolumeInformation(drv, _root._volname, _MAX_FNAME, 0, 0, &_root._fs_flags, _root._fs, _MAX_DIR); lstrcpy(_root._path, drv); _root._entry = new WinDirectory(_root._path); - entry = _root._entry->read_tree(info._path, SORT_NAME/*_sortOrder*/); + entry = _root._entry->read_tree(info._path, SORT_NAME); } if (info._etype != ET_SHELL) diff --git a/reactos/subsys/system/explorer/shell/ntobjfs.cpp b/reactos/subsys/system/explorer/shell/ntobjfs.cpp index e1f104b70b6..e51bb729e3b 100644 --- a/reactos/subsys/system/explorer/shell/ntobjfs.cpp +++ b/reactos/subsys/system/explorer/shell/ntobjfs.cpp @@ -149,23 +149,23 @@ struct UnicodeString : public RtlUnicodeString { }; -static DWORD NtOpenObject(OBJECT_TYPE type, HANDLE* phandle, DWORD flags, LPCWSTR path/*, BOOL xflag=FALSE*/) +static DWORD NtOpenObject(OBJECT_TYPE type, HANDLE* phandle, DWORD access, LPCWSTR path/*, BOOL xflag=FALSE*/) { UnicodeString ustr(path); OpenStruct open_struct = {sizeof(OpenStruct), 0x00, &ustr, 0x40}; if (type==SYMBOLICLINK_OBJECT || type==DIRECTORY_OBJECT) - flags |= 1; //@@ ENUMERATE + access |= FILE_LIST_DIRECTORY; /* if (xflag) - flags |= 0x80000000; */ + access |= GENERIC_READ; */ - DWORD retx; + DWORD ioStatusBlock[2]; // IO_STATUS_BLOCK if (type>=DIRECTORY_OBJECT && type<=IOCOMPLETITION_OBJECT) - return g_NTDLL->_ObjectOpenFunctions[type](phandle, flags|0x20000, &open_struct); + return g_NTDLL->_ObjectOpenFunctions[type](phandle, access|STANDARD_RIGHTS_READ, &open_struct); else if (type == FILE_OBJECT) - return (*g_NTDLL->NtOpenFile)(phandle, flags, &open_struct, &retx, 7, 0); + return (*g_NTDLL->NtOpenFile)(phandle, access, &open_struct, ioStatusBlock, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0/*OpenOptions*/); else return ERROR_INVALID_FUNCTION; } @@ -199,7 +199,7 @@ void NtObjDirectory::read_directory(int scan_flags) --w; #endif - DWORD idx1, idx2; + DWORD idx; HANDLE dir_handle; #ifdef UNICODE @@ -218,9 +218,9 @@ void NtObjDirectory::read_directory(int scan_flags) #endif if (_type == DIRECTORY_OBJECT) { - NtObjectInfo* info = (NtObjectInfo*)alloca(0x800); + NtObjectInfo* info = (NtObjectInfo*)alloca(2048); - if (!(*g_NTDLL->NtQueryDirectoryObject)(dir_handle, info, 0x800, TRUE, TRUE, &idx1, &idx2)) { + if (!(*g_NTDLL->NtQueryDirectoryObject)(dir_handle, info, 2048, TRUE, TRUE, &idx, NULL)) { WIN32_FIND_DATA w32fd; Entry* last = NULL; Entry* entry; @@ -288,7 +288,7 @@ void NtObjDirectory::read_directory(int scan_flags) NtObject object; DWORD read; - if (!(*g_NTDLL->NtQueryObject)(handle, 0, &object, sizeof(NtObject), &read)) { + if (!(*g_NTDLL->NtQueryObject)(handle, 0/*ObjectBasicInformation*/, &object, sizeof(NtObject), &read)) { memcpy(&w32fd.ftCreationTime, &object.creation_time, sizeof(FILETIME)); memset(&entry->_bhfi, 0, sizeof(BY_HANDLE_FILE_INFORMATION)); @@ -313,7 +313,7 @@ void NtObjDirectory::read_directory(int scan_flags) entry->_level = level; last = entry; - } while(!(*g_NTDLL->NtQueryDirectoryObject)(dir_handle, info, 0x800, TRUE, FALSE, &idx1, &idx2)); + } while(!(*g_NTDLL->NtQueryDirectoryObject)(dir_handle, info, 2048, TRUE, FALSE, &idx, NULL)); last->_next = NULL; } diff --git a/reactos/subsys/system/explorer/shell/regfs.cpp b/reactos/subsys/system/explorer/shell/regfs.cpp index 3ca1ce62fb3..79c2ac93aeb 100644 --- a/reactos/subsys/system/explorer/shell/regfs.cpp +++ b/reactos/subsys/system/explorer/shell/regfs.cpp @@ -242,7 +242,7 @@ RegDirectory::RegDirectory(Entry* parent, LPCTSTR path, HKEY hKeyRoot) void RegistryRoot::read_directory(int scan_flags) { - Entry *entry, *last; + Entry *entry, *last, *first_entry; int level = _level + 1; _data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; @@ -251,7 +251,7 @@ void RegistryRoot::read_directory(int scan_flags) _tcscpy(entry->_data.cFileName, TEXT("HKEY_CURRENT_USER")); entry->_level = level; - _down = entry; + first_entry = entry; last = entry; entry = new RegDirectory(this, TEXT("\\"), HKEY_LOCAL_MACHINE); @@ -297,4 +297,7 @@ void RegistryRoot::read_directory(int scan_flags) last = entry; */ last->_next = NULL; + + _down = first_entry; + _scanned = true; }