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
This commit is contained in:
Vadim Zeitlin
2008-07-17 23:01:02 +00:00
parent 55f7a9ec3c
commit 852dcba528

View File

@@ -543,7 +543,7 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen,
const char *src, size_t srcLen) const const char *src, size_t srcLen) const
{ {
DecoderState stateOrig, DecoderState stateOrig,
*statePtr; *statePtr;
if ( srcLen == wxNO_LEN ) if ( srcLen == wxNO_LEN )
{ {
// convert the entire string, up to and including the trailing NUL // 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]; const unsigned char dc = utf7unb64[cc];
if ( dc == 0xff ) 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(); state.ToDirect();
// re-parse this character normally below unless it's '-' which // 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? // start of an encoded segment?
if ( cc == '+' ) if ( cc == '+' )
{ {
if ( src == srcEnd )
return wxCONV_FAILED; // can't have '+' at the end
if ( *src == '-' ) if ( *src == '-' )
{ {
// just the encoded plus sign, don't switch to shifted mode // just the encoded plus sign, don't switch to shifted mode