From:             
Operating system: CentOS 5.5
PHP version:      Irrelevant
Package:          IMAP related
Bug Type:         Bug
Bug description:Buffer overflow error in imap_headerinfo can not be suppressed

Description:
------------
This is related to https://bugs.php.net/bug.php?id=50977

There are really two bugs here:
1 - the bug linked above - the buffer overflow when a message has too many
addresses in the "To: " field (my test case had 580+)

2 - The fact that I can not suppress the error and continue script
execution

Here is the error that is generated due to #1:

[Mon Sep 12 17:14:42 2011] [error] [client 10.1.XXX.XXX] PHP Fatal error: 
imap_headerinfo() [<a
href='function.imap-headerinfo'>function.imap-headerinfo</a>]: Address
buffer overflow in /home/jrthomer/XXXXX/trunk/www/lib/imap.php on line 805,
referer: https://example.com/jrthomer_qa/index.php

The imap_headerinfo call never returns.  The script is aborted.

The bigger problem is that no attempt at suppressing the error and
continuing processing is working.  Typically we can catch an error like
this with a try/catch if the function returns an exception.  If it does not
(worst case scenario), we can suppress all errors with the "@" prefix
before the function call.  In this case, neither worked.  Additionally, I
tried set_error_handler with a custom error handler.  The error handler
catches errors that I manually trigger using trigger_error (and the script
continues processing), but it does *not* get called for the error that is
pasted above.  

The script below is an example that shows all the error handling methods I
have tried that are not working.



Test script:
---------------
function suppress_all_errors($errno, $errstr, $errfile, $errline) {
   print("there was an error calling imap_headerinfo {$errno}, {$errstr},
{$errfile}, {$errline}");
};

function getMessageHeaderInfo($objConn, $intUID, $blFullAttachmentDetails =
false) {
   $intMessageNumber = imap_msgno($objConn, $intUID); // this works (in
other words, connection and message UID are okay)

   $objHdr = false;
   try {
      set_error_handler("suppress_all_errors", E_ALL);

      // this error ends up in my error "suppress_all_errors" error
handler
      trigger_error("test", E_ERROR); 

      // the following line results in an error in the logs and aborts the
script
      // note that the try/catch does not work (no exception is thrown), 
      // the @ error suppressor does not work (the error is still logged
and the script is aborted)
      // and the custom error handler set above does not get triggered
      $objHdr = @imap_headerinfo($objConn, $intMessageNumber); // <---
ERROR IS HERE
      restore_error_handler(); 
   } catch (Exception $e) {
      print("error getting imap_headerinfo: {$e}");
   }
}

Expected result:
----------------
Two expected results:

1 - there should not be a buffer overflow

2 - in the event of the buffer overflow, I should be able to continue
script execution


-- 
Edit bug report at https://bugs.php.net/bug.php?id=55675&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55675&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55675&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55675&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55675&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55675&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55675&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55675&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55675&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55675&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55675&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55675&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55675&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55675&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55675&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55675&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55675&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55675&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55675&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55675&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55675&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55675&r=mysqlcfg

Reply via email to