From: Vadim Zeitlin Date: Thu, 17 Jul 2008 23:01:02 +0000 (+0000) Subject: properly detect missing data at the end of UTF-7-encoded segment and fail the convers... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/852dcba5286b2b423d7cb21799d11df7efcbd0e6 properly detect missing data at the end of UTF-7-encoded segment and fail the conversion in this case git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54670 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 54ac2c8489..5d19539fc5 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -543,7 +543,7 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen, const char *src, size_t srcLen) const { DecoderState stateOrig, - *statePtr; + *statePtr; if ( srcLen == wxNO_LEN ) { // convert the entire string, up to and including the trailing NUL @@ -580,7 +580,12 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen, const unsigned char dc = utf7unb64[cc]; if ( dc == 0xff ) { - // end of encoded part + // end of encoded part, check that nothing was left: the bit + // field cycles through 0,6,4,2 sequence so check that we're at + // the end of it + if ( state.bit != 2 ) + return wxCONV_FAILED; + state.ToDirect(); // re-parse this character normally below unless it's '-' which @@ -624,9 +629,6 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen, // start of an encoded segment? if ( cc == '+' ) { - if ( src == srcEnd ) - return wxCONV_FAILED; // can't have '+' at the end - if ( *src == '-' ) { // just the encoded plus sign, don't switch to shifted mode