Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv399/src/gui

Modified Files:
        wxFolderTree.cpp 
Log Message:
fixed buffer overrun in UTF-7 conversion code (bug 779)

Index: wxFolderTree.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxFolderTree.cpp,v
retrieving revision 1.214
retrieving revision 1.215
diff -b -u -2 -r1.214 -r1.215
--- wxFolderTree.cpp    29 Aug 2003 00:10:01 -0000      1.214
+++ wxFolderTree.cpp    1 Sep 2003 01:07:43 -0000       1.215
@@ -1547,10 +1547,12 @@
 wxString wxFolderTreeNode::GetName() const
 {
-   wxString name, nameutf7, nameutf8;
-   wxString nameOrig = m_folder->GetName();
+   const wxString nameOrig = m_folder->GetName();
+   wxString name;
 
    bool isValid = true;
 
-   size_t len = nameOrig.Length();
+   const size_t len = nameOrig.Length();
+
+   name.reserve(len);
    for ( size_t i = 0; i < len; i++ )
    {
@@ -1559,5 +1561,5 @@
       if (s & 0x80)
       {
-         /* reserved for future use with UTF-8 */
+         // reserved for future use with UTF-8
          wxLogDebug(_T("mailbox name with 8-bit character"));
          isValid = false;
@@ -1568,7 +1570,7 @@
       if (s == '&')
       {
-         nameutf7 = '+';
+         String nameutf7 = '+';
          size_t j = i;
-         while ( (s = nameOrig[++j]) != '-')
+         while ( ((s = nameOrig[++j]) != '-') && isValid )
          {
             switch (s)
@@ -1578,4 +1580,16 @@
                   isValid = false;
                   break;
+
+#if 0
+               case '+':   /* valid modified BASE64 */
+                  // but we don't support it yet  FIXME
+                  isValid = false;
+                  break;
+               case ',':  /* all OK so far */
+                  // but we don't support it yet; should be changed to "/"  FIXME
+                  isValid = false;
+                  break;
+#endif // 0
+
                default:    /* must be alphanumeric */
                   if (!isalnum (s))
@@ -1589,19 +1603,10 @@
                      nameutf7 << s;
                   }
-#if 0
-               case '+':   /* valid modified BASE64 */
-                  // but we don't support it yet  FIXME
-                  isValid = false;
-                  break;
-               case ',':  /* all OK so far */
-                  // but we don't support it yet; should be changed to "/"  FIXME
-                  isValid = false;
-                  break;
-#endif
             }
-         } //end while
+         }
+
+         if ( !isValid )
+            break;
 
-         if (isValid)
-         {
             // valid IMAP modified UTF-7 mailbox name, converting to
             // environment's default encoding for now (FIXME)
@@ -1624,4 +1629,6 @@
             //we cannot use "nameutf8 << text8->data" here as utf8_text_utf7()
             //returns text8->data which is longer than text8->size:
+         String nameutf8;
+         nameutf8.reserve(text8->size);
             for ( unsigned long k = 0; k < text8->size; k++ )
             {
@@ -1635,17 +1642,11 @@
             free(text8);
          }
-      }
       else // s != '&'
       {
          name << s;
       }
-   } //end for
-
-   if ( isValid )
-   {
-      return name;
    }
 
-   return nameOrig;
+   return isValid ? name : nameOrig;
 }
 



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to