From: Vadim Zeitlin Date: Wed, 9 Jul 2003 22:35:56 +0000 (+0000) Subject: added some checks for .mo integrity (part of patch 649438) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/869c75498a12e470b610f22ff24f69401b359cd4 added some checks for .mo integrity (part of patch 649438) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21822 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 69178b2abc..b8d28fdb0d 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -188,21 +188,37 @@ private: // all data is stored here, NULL if no data loaded size_t8 *m_pData; + // amount of memory pointed to by m_pData. + size_t32 m_nSize; + // data description size_t32 m_numStrings; // number of strings in this domain wxMsgTableEntry *m_pOrigTable, // pointer to original strings *m_pTransTable; // translated - const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 index) const - { return (const char *)(m_pData + Swap(pTable[index].ofsString)); } + // swap the 2 halves of 32 bit integer if needed + size_t32 Swap(size_t32 ui) const + { + return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) | + ((ui >> 8) & 0xff00) | (ui >> 24) + : ui; + } - wxString GetCharset() const; + const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const + { + const wxMsgTableEntry * const ent = pTable + n; - // utility functions - // big<->little endian - inline size_t32 Swap(size_t32 ui) const; + // this check could fail for a corrupt message catalog + size_t32 ofsString = Swap(ent->ofsString); + if ( ofsString + Swap(ent->nLen) > m_nSize) + return NULL; - bool m_bSwapped; // wrong endianness? + return (const char *)(m_pData + ofsString); + } + + wxString GetCharset() const; + + bool m_bSwapped; // wrong endianness? DECLARE_NO_COPY_CLASS(wxMsgCatalogFile) }; @@ -250,22 +266,15 @@ static wxArrayString s_searchPrefixes; // wxMsgCatalogFile class // ---------------------------------------------------------------------------- -// swap the 2 halves of 32 bit integer if needed -size_t32 wxMsgCatalogFile::Swap(size_t32 ui) const -{ - return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) | - ((ui >> 8) & 0xff00) | (ui >> 24) - : ui; -} - wxMsgCatalogFile::wxMsgCatalogFile() { - m_pData = NULL; + m_pData = NULL; + m_nSize = 0; } wxMsgCatalogFile::~wxMsgCatalogFile() { - wxDELETEA(m_pData); + wxDELETEA(m_pData); } // return all directories to search for given prefix @@ -414,6 +423,7 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName0) Swap(pHeader->ofsOrigTable)); m_pTransTable = (wxMsgTableEntry *)(m_pData + Swap(pHeader->ofsTransTable)); + m_nSize = nSize; // everything is fine return TRUE;