php.net |  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: jmessa@php.net Assigned: iliaa (profile)
Status: Closed Package: IMAP related
PHP Version: 5.2CVS-2008-04-01 (snap) OS: Windows XP
Private report: No CVE-ID: None
 [2008-04-01 15:54 UTC] jmessa@php.net
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));
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-02 16:32 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


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


Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC