[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    [PATCH] 3.1.x: Two very wrong, but non-critical bugs
From:       Marc Mutz <mutz () kde ! org>
Date:       2003-07-17 10:56:20
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi!

Attached patch fixes two things I've come across while cleaning up code 
in kmmsgbase:

1. The first is just an off-by-one error, combined with flipping the two 
operands of a difference.

In this situation, "mid" points to after the third '?' of an 
encoded-word (ie. to the first char of the encoded-text), while "pos" 
points to the fourth and last '?' of the encoded-word, ie. one after 
the last char of the encoded-text.

Thus, mid - pos - 1 is in general negative (or huge if cast to an 
unsigned), thus left() is a noop-here. But if someone (like me) wants 
to get rid of the *pos=0 hack, then the result crashes.

The correct fix is to use QCString( mid, pos - mid + 1 ) to construct 
"str".

2. No comment. Just let the original code sink in.

OK to commit?

Marc

-- 
I am Bush of USA. You will be pacified. Resistance is futile.

["kmmsgbase.cpp.diff" (text/x-diff)]

Index: kmmsgbase.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/Attic/kmmsgbase.cpp,v
retrieving revision 1.125
diff -u -3 -p -r1.125 kmmsgbase.cpp
--- 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=0;
   QCString str, cstr, LWSP_buffer;
-  char encoding='Q', ch;
+  char encoding='Q';
   bool valid, lastWasEncodedWord=FALSE;
   const int maxLen=200;
   int i;
@@ -421,9 +421,7 @@ QString KMMsgBase::decodeRFC2047String(c
     if (valid)
     {
       // valid encoding: decode and throw away separating LWSP
-      ch = *pos;
-      *pos = '\0';
-      str = QCString(mid).left((int)(mid - pos - 1));
+      str = QCString(mid, pos-mid+1 /* +1 adds trailing NUL */);
       if (encoding == 'Q')
       {
 	// decode quoted printable text
@@ -441,7 +439,6 @@ QString KMMsgBase::decodeRFC2047String(c
       result += codec->toUnicode(cstr);
       lastWasEncodedWord = TRUE;
 
-      *pos = ch;
       pos = end -1;
     }
     else
@@ -646,13 +643,10 @@ QString KMMsgBase::decodeRFC2231String(c
     }
     p++;
   }
-  QString result;
   QTextCodec *codec = codecForName(charset);
   if (!codec) codec = kernel->networkCodec();
-  if (codec) result = codec->toUnicode(st);
-  else result = kernel->networkCodec()->toUnicode(st);
-
-  return result;
+  assert( codec );
+  return codec->toUnicode(st);
 }
 
 //-----------------------------------------------------------------------------

[Attachment #8 (application/pgp-signature)]

_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic