On Linux you can fopen (read) a directory for no reason, fix SafeReadFile to make it safer

TIL
This commit is contained in:
Marek Roszko 2025-05-01 23:25:45 -04:00
parent 157180e772
commit 883a1f8d97

View File

@ -95,6 +95,12 @@ std::string StrPrintf( const char* format, ... )
wxString SafeReadFile( const wxString& aFilePath, const wxString& aReadType )
{
// Check the path exists as a file first
// the IsOpened check would be logical, but on linux you can fopen (in read mode) a directory
// And then everything else in here will barf
if( !wxFileExists( aFilePath ) )
THROW_IO_ERROR( wxString::Format( _( "File '%s' does not exist." ), aFilePath ) );
wxString contents;
wxFFile ff( aFilePath );