git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58106
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
wxLocale::AddCatalogLookupPathPrefix(wxT("."));
// Initialize the catalogs we'll be using
wxLocale::AddCatalogLookupPathPrefix(wxT("."));
// Initialize the catalogs we'll be using
- m_locale.AddCatalog(wxT("internat"));
+ if (!m_locale.AddCatalog(wxT("internat")))
+ wxLogError(_("Couldn't find/load the 'internat' catalog."));
// this catalog is installed in standard location on Linux systems and
// shows that you may make use of the standard message catalogs as well
// this catalog is installed in standard location on Linux systems and
// shows that you may make use of the standard message catalogs as well
// wxMsgCatalogFile corresponds to one disk-file message catalog.
//
// This is a "low-level" class and is used only by wxMsgCatalog
// wxMsgCatalogFile corresponds to one disk-file message catalog.
//
// This is a "low-level" class and is used only by wxMsgCatalog
+// NOTE: for the documentation of the binary catalog (.MO) files refer to
+// the GNU gettext manual:
+// http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html
// ----------------------------------------------------------------------------
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxString, wxMessagesHash);
// ----------------------------------------------------------------------------
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxString, wxMessagesHash);
// load the catalog from disk (szDirPrefix corresponds to language)
bool Load(const wxString& szDirPrefix, const wxString& szName,
// load the catalog from disk (szDirPrefix corresponds to language)
bool Load(const wxString& szDirPrefix, const wxString& szName,
- wxPluralFormsCalculatorPtr& rPluralFormsCalculator);
+ wxPluralFormsCalculatorPtr& rPluralFormsCalculator);
// fills the hash with string-translation pairs
// fills the hash with string-translation pairs
- void FillHash(wxMessagesHash& hash,
- const wxString& msgIdCharset,
- bool convertEncoding) const;
+ bool FillHash(wxMessagesHash& hash,
+ const wxString& msgIdCharset,
+ bool convertEncoding) const;
// return the charset of the strings in this catalog or empty string if
// none/unknown
// return the charset of the strings in this catalog or empty string if
// none/unknown
-void wxMsgCatalogFile::FillHash(wxMessagesHash& hash,
+bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash,
const wxString& msgIdCharset,
bool convertEncoding) const
{
const wxString& msgIdCharset,
bool convertEncoding) const
{
for (size_t32 i = 0; i < m_numStrings; i++)
{
const char *data = StringAtOfs(m_pOrigTable, i);
for (size_t32 i = 0; i < m_numStrings; i++)
{
const char *data = StringAtOfs(m_pOrigTable, i);
+ if (!data)
+ return false; // may happen for invalid MO files
wxString msgid;
#if wxUSE_UNICODE
wxString msgid;
#if wxUSE_UNICODE
#endif // wxUSE_UNICODE
data = StringAtOfs(m_pTransTable, i);
#endif // wxUSE_UNICODE
data = StringAtOfs(m_pTransTable, i);
+ if (!data)
+ return false; // may happen for invalid MO files
+
size_t length = Swap(m_pTransTable[i].nLen);
size_t offset = 0;
size_t index = 0;
size_t length = Swap(m_pTransTable[i].nLen);
size_t offset = 0;
size_t index = 0;
- offset += strlen(str) + 1;
+ // IMPORTANT: accesses to the 'data' pointer are valid only for
+ // the first 'length+1' bytes (GNU specs says that the
+ // final NUL is not counted in length); using wxStrnlen()
+ // we make sure we don't access memory beyond the valid range
+ // (which otherwise may happen for invalid MO files):
+ offset += wxStrnlen(str, length - offset) + 1;
delete sourceConv;
delete inputConvPtr;
#endif // wxUSE_WCHAR_T
delete sourceConv;
delete inputConvPtr;
#endif // wxUSE_WCHAR_T
if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) )
return false;
if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) )
return false;
- file.FillHash(m_messages, msgIdCharset, bConvertEncoding);
+ if ( !file.FillHash(m_messages, msgIdCharset, bConvertEncoding) )
+ return false;
#if !wxUSE_UNICODE
// we should use a conversion compatible with the message catalog encoding
#if !wxUSE_UNICODE
// we should use a conversion compatible with the message catalog encoding