From kmail-devel Thu Jul 17 10:56:20 2003 From: Marc Mutz Date: Thu, 17 Jul 2003 10:56:20 +0000 To: kmail-devel Subject: [PATCH] 3.1.x: Two very wrong, but non-critical bugs X-MARC-Message: https://marc.info/?l=kmail-devel&m=105844011009851 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============13052657318296657==" --===============13052657318296657== Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Boundary-03=_UDoF/lRWXxG4aPL"; charset="us-ascii" Content-Transfer-Encoding: 7bit --Boundary-03=_UDoF/lRWXxG4aPL Content-Type: multipart/mixed; boundary="Boundary-01=_UDoF/LkKV770Dqh" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_UDoF/LkKV770Dqh Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi! Attached patch fixes two things I've come across while cleaning up code=20 in kmmsgbase: 1. The first is just an off-by-one error, combined with flipping the two=20 operands of a difference. In this situation, "mid" points to after the third '?' of an=20 encoded-word (ie. to the first char of the encoded-text), while "pos"=20 points to the fourth and last '?' of the encoded-word, ie. one after=20 the last char of the encoded-text. Thus, mid - pos - 1 is in general negative (or huge if cast to an=20 unsigned), thus left() is a noop-here. But if someone (like me) wants=20 to get rid of the *pos=3D0 hack, then the result crashes. The correct fix is to use QCString( mid, pos - mid + 1 ) to construct=20 "str". 2. No comment. Just let the original code sink in. OK to commit? Marc =2D-=20 I am Bush of USA. You will be pacified. Resistance is futile. --Boundary-01=_UDoF/LkKV770Dqh Content-Type: text/x-diff; charset="us-ascii"; name="kmmsgbase.cpp.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="kmmsgbase.cpp.diff" Index: kmmsgbase.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdenetwork/kmail/Attic/kmmsgbase.cpp,v retrieving revision 1.125 diff -u -3 -p -r1.125 kmmsgbase.cpp =2D-- kmmsgbase.cpp 2 Nov 2002 21:00:52 -0000 1.125 +++ kmmsgbase.cpp 17 Jul 2003 10:59:23 -0000 @@ -336,7 +336,7 @@ QString KMMsgBase::decodeRFC2047String(c QCString charset; char *pos, *beg, *end, *mid=3D0; QCString str, cstr, LWSP_buffer; =2D char encoding=3D'Q', ch; + char encoding=3D'Q'; bool valid, lastWasEncodedWord=3DFALSE; const int maxLen=3D200; int i; @@ -421,9 +421,7 @@ QString KMMsgBase::decodeRFC2047String(c if (valid) { // valid encoding: decode and throw away separating LWSP =2D ch =3D *pos; =2D *pos =3D '\0'; =2D str =3D QCString(mid).left((int)(mid - pos - 1)); + str =3D QCString(mid, pos-mid+1 /* +1 adds trailing NUL */); if (encoding =3D=3D 'Q') { // decode quoted printable text @@ -441,7 +439,6 @@ QString KMMsgBase::decodeRFC2047String(c result +=3D codec->toUnicode(cstr); lastWasEncodedWord =3D TRUE; =20 =2D *pos =3D ch; pos =3D end -1; } else @@ -646,13 +643,10 @@ QString KMMsgBase::decodeRFC2231String(c } p++; } =2D QString result; QTextCodec *codec =3D codecForName(charset); if (!codec) codec =3D kernel->networkCodec(); =2D if (codec) result =3D codec->toUnicode(st); =2D else result =3D kernel->networkCodec()->toUnicode(st); =2D =2D return result; + assert( codec ); + return codec->toUnicode(st); } =20 //------------------------------------------------------------------------= =2D---- --Boundary-01=_UDoF/LkKV770Dqh-- --Boundary-03=_UDoF/lRWXxG4aPL Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQA/FoDU3oWD+L2/6DgRAnrxAKDnb9uuJVpf77V2qCNfuI4/MSg9kACgmbCb bxDWBhdi/PReUC1Ua9zw1as= =nv2/ -----END PGP SIGNATURE----- --Boundary-03=_UDoF/lRWXxG4aPL-- --===============13052657318296657== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ KMail Developers mailing list kmail@mail.kde.org http://mail.kde.org/mailman/listinfo/kmail --===============13052657318296657==--