Don't use values returned by lstat() if it failed in wxFileCtrl code.

The buffer may be uninitialized or at least not contain the correct data if
lstat() failed, don't use it in this case.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-12-08 00:37:28 +00:00
parent bd9fd76ec7
commit 4d35172f52

View File

@@ -223,32 +223,39 @@ void wxFileData::ReadData()
wxStructStat buff;
#if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS))
lstat( m_filePath.fn_str(), &buff );
m_type |= S_ISLNK(buff.st_mode) ? is_link : 0;
const bool hasStat = lstat( m_filePath.fn_str(), &buff ) == 0;
if ( hasStat )
m_type |= S_ISLNK(buff.st_mode) ? is_link : 0;
#else // no lstat()
wxStat( m_filePath, &buff );
const bool hasStat = wxStat( m_filePath, &buff ) == 0;
#endif
m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
if ( hasStat )
{
m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
m_size = buff.st_size;
m_size = buff.st_size;
m_dateTime = buff.st_mtime;
m_dateTime = buff.st_mtime;
}
#endif
// __WXWINCE__
#if defined(__UNIX__)
m_permissions.Printf(wxT("%c%c%c%c%c%c%c%c%c"),
buff.st_mode & wxS_IRUSR ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWUSR ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXUSR ? wxT('x') : wxT('-'),
buff.st_mode & wxS_IRGRP ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWGRP ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXGRP ? wxT('x') : wxT('-'),
buff.st_mode & wxS_IROTH ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWOTH ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXOTH ? wxT('x') : wxT('-'));
if ( hasStat )
{
m_permissions.Printf(wxT("%c%c%c%c%c%c%c%c%c"),
buff.st_mode & wxS_IRUSR ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWUSR ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXUSR ? wxT('x') : wxT('-'),
buff.st_mode & wxS_IRGRP ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWGRP ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXGRP ? wxT('x') : wxT('-'),
buff.st_mode & wxS_IROTH ? wxT('r') : wxT('-'),
buff.st_mode & wxS_IWOTH ? wxT('w') : wxT('-'),
buff.st_mode & wxS_IXOTH ? wxT('x') : wxT('-'));
}
#elif defined(__WIN32__)
DWORD attribs = ::GetFileAttributes(m_filePath.c_str());
if (attribs != (DWORD)-1)