iliaa           Tue Feb 11 17:57:22 2003 EDT

  Modified files:              
    /php4/ext/imap      php_imap.c 
  Log:
  Fixed bug #22048 (crash in imap_headers when the e-mail contains an 
  abnormally large number of special characters).
  
  
Index: php4/ext/imap/php_imap.c
diff -u php4/ext/imap/php_imap.c:1.158 php4/ext/imap/php_imap.c:1.159
--- php4/ext/imap/php_imap.c:1.158      Mon Feb  3 16:24:32 2003
+++ php4/ext/imap/php_imap.c    Tue Feb 11 17:57:22 2003
@@ -26,7 +26,7 @@
    | PHP 4.0 updates:  Zeev Suraski <[EMAIL PROTECTED]>                       |
    +----------------------------------------------------------------------+
  */
-/* $Id: php_imap.c,v 1.158 2003/02/03 21:24:32 iliaa Exp $ */
+/* $Id: php_imap.c,v 1.159 2003/02/11 22:57:22 iliaa Exp $ */
 
 #define IMAP41
 
@@ -3549,6 +3549,34 @@
 }
 /* }}} */
 
+/* {{{ _php_rfc822_len
+ * Calculate string length based on imap's rfc822_cat function.
+ */    
+static int _php_rfc822_len(char *str)
+{
+       int len;
+       char *p;
+
+       if (!str || !*str) {
+               return 0;
+       }
+
+       /* strings with special characters will need to be quoted, as a safety measure 
+we
+        * add 2 bytes for the quotes just in case.
+        */
+       len = strlen(str) + 2;
+       p = str;
+       /* rfc822_cat() will escape all " and \ characters, therefor we need to 
+increase
+        * our buffer length to account for these characters.
+        */
+       while ((p = strpbrk(p, "\\\""))) {
+               p++;
+               len++;
+       }
+
+       return len;
+}
+/* }}} */
 
 /* Support Functions */
 /* {{{ _php_imap_get_address_size
@@ -3561,10 +3589,10 @@
        tmp = addresslist;
 
        if (tmp) do {
-               ret += (tmp->personal) ? strlen(tmp->personal) : 0;
-               ret += (tmp->adl)      ? strlen(tmp->adl)      : 0;
-               ret += (tmp->mailbox)  ? strlen(tmp->mailbox)  : 0;
-               ret += (tmp->host)     ? strlen(tmp->host)     : 0;
+               ret += _php_rfc822_len(tmp->personal);
+               ret += _php_rfc822_len(tmp->adl);
+               ret += _php_rfc822_len(tmp->mailbox);
+               ret += _php_rfc822_len(tmp->host);
                num_ent++;
        } while ((tmp = tmp->next));
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to