|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44594 unsigned long passed as $n_retries argument to imap_open()
Submitted: 2008-04-01 15:54 UTC Modified: 2008-04-17 11:05 UTC
From: Assigned: iliaa
Status: Closed Package: IMAP related
PHP Version: 5.2CVS-2008-04-01 (snap) OS: Windows XP
Private report: No CVE-ID:
 [2008-04-01 15:54 UTC]
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: 

	if (myargc == 5) {
		mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) Z_LVAL_PP(retries));


	if (myargc == 5) {

		if (retries < 1) { 
			php_error_docref(NULL TSRMLS_CC, E_WARNING ,"Retries cannot be less than 1");

		mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) Z_LVAL_PP(retries));

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:
var_dump(imap_open($mailbox, $username, $password, null, -1));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-02 16:32 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2008-04-17 08:47 UTC]
I'm still having this problem with the most recent snapshot
 [2008-04-17 11:05 UTC]
Hi Josie, i have fixed a typo in the fix.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 14:01:32 2015 UTC