X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/80fdb8d64f1ddecdef2d987d79871b5b508930c0..785f5eaa05195f5e44a974861864324667a3326e:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 9899d67a9d..f2118e743e 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -494,10 +494,21 @@ wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv) wxString strTmp; char buf[1024]; - while ( !inStream.Read(buf, WXSIZEOF(buf)).Eof() ) - strTmp.append(wxConvertMB2WX(buf), inStream.LastRead()); + do + { + inStream.Read(buf, WXSIZEOF(buf)); - strTmp.append(wxConvertMB2WX(buf), inStream.LastRead()); + const wxStreamError err = inStream.GetLastError(); + + if ( err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF ) + { + wxLogError(_("Error reading config options.")); + break; + } + + strTmp.append(wxConvertMB2WX(buf), inStream.LastRead()); + } + while ( !inStream.Eof() ); strTrans = wxTextBuffer::Translate(strTmp); } @@ -652,7 +663,7 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal) } else { // a key const wxChar *pEnd = pStart; - while ( *pEnd && *pEnd != wxT('=') && !wxIsspace(*pEnd) ) { + while ( *pEnd && *pEnd != wxT('=') /* && !wxIsspace(*pEnd)*/ ) { if ( *pEnd == wxT('\\') ) { // next character may be space or not - still take it because it's // quoted (unless there is nothing) @@ -666,7 +677,7 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal) pEnd++; } - wxString strKey(FilterInEntryName(wxString(pStart, pEnd))); + wxString strKey(FilterInEntryName(wxString(pStart, pEnd).Trim())); // skip whitespace while ( wxIsspace(*pEnd) ) @@ -1090,8 +1101,11 @@ bool wxFileConfig::DeleteAll() { CleanUp(); - if ( wxRemove(m_strLocalFile) == -1 ) - wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str()); + if ( wxFile::Exists(m_strLocalFile) && wxRemove(m_strLocalFile) == -1 ) + { + wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str()); + return FALSE; + } m_strLocalFile = m_strGlobalFile = wxT(""); Init(); @@ -2007,14 +2021,22 @@ static wxString FilterOutEntryName(const wxString& str) strResult.Alloc(str.Len()); for ( const wxChar *pc = str.c_str(); *pc != wxT('\0'); pc++ ) { - wxChar c = *pc; + const wxChar c = *pc; // we explicitly allow some of "safe" chars and 8bit ASCII characters - // which will probably never have special meaning + // which will probably never have special meaning and with which we can't + // use isalnum() anyhow (in ASCII built, in Unicode it's just fine) + // // NB: note that wxCONFIG_IMMUTABLE_PREFIX and wxCONFIG_PATH_SEPARATOR // should *not* be quoted - if ( !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) && ((c & 0x80) == 0) ) + if ( +#if !wxUSE_UNICODE + ((unsigned char)c < 127) && +#endif // ANSI + !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) ) + { strResult += wxT('\\'); + } strResult += c; }