From: [EMAIL PROTECTED] Operating system: Windows XP PHP version: 5.2CVS-2008-04-01 (snap) PHP Bug Type: IMAP related Bug description: unsigned long passed as $n_retries argument to imap_open()
Description: ------------ When a negative integer is passed as the $n_retries argument to imap_open(), the number is passed as a signed long to the c-client function mail_parameters(), which is expecting an unsigned long to be passed on a SET_MAXLOGINTRIALS call. This results in $n_retries being set to a huge number. The problem is the the function php_imap_do_open() in ext/imap/php_imap.c. Below is a patch written by Andy Wharmby (CVS ID wharmby), it returns a warning if $n_retries is less than 0: The code as it stands is: #ifdef SET_MAXLOGINTRIALS if (myargc == 5) { convert_to_long_ex(retries); mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) Z_LVAL_PP(retries)); } #endif SOLUTION: #ifdef SET_MAXLOGINTRIALS if (myargc == 5) { convert_to_long_ex(retries); if (retries < 1) { php_error_docref(NULL TSRMLS_CC, E_WARNING ,"Retries cannot be less than 1"); RETURN_FALSE; } mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) Z_LVAL_PP(retries)); } #endif The documentation for the $n_retries argument also says that the number passed is "Number of maximum connect attempts" which is incorrect. There is always one attempt to connect, if that fails then $n_retries sets how many more attempts are made *after* the initial attempt. Reproduce code: --------------- <?php var_dump(imap_open($mailbox, $username, $password, null, -1)); ?> -- Edit bug report at http://bugs.php.net/?id=44594&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44594&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44594&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44594&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44594&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44594&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44594&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44594&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44594&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44594&r=support Expected behavior: http://bugs.php.net/fix.php?id=44594&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44594&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44594&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44594&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44594&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44594&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44594&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44594&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44594&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44594&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44594&r=mysqlcfg