php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80800 imap_open() fails when the flags parameter includes CL_EXPUNGE
Submitted: 2021-02-25 15:49 UTC Modified: 2021-02-27 13:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phplist at dcameron dot me dot uk Assigned: girgias (profile)
Status: Closed Package: IMAP related
PHP Version: 8.0.0 OS:
Private report: No CVE-ID: None
 [2021-02-25 15:49 UTC] phplist at dcameron dot me dot uk
Description:
------------
Code to open a mailbox using imap_open() works fine for php 7 and earlier but fails with php 8. This is when the fourth parameter is set to CL_EXPUNGE. If any other valid flag is used, such as OP_DEBUG, then the open is successful.

IMAP c-Client Version 	2007f

Looking at the c code for the imap extension, php 8 has some extra validation of the flags parameter. This is the line that throws the error

	if (flags && ((flags & ~(OP_READONLY | OP_ANONYMOUS | OP_HALFOPEN | CL_EXPUNGE | OP_DEBUG | OP_SHORTCACHE
	 		| OP_SILENT | OP_PROTOTYPE | OP_SECURE)) != 0)) {

https://github.com/php/php-src/commit/25569679aae88af948ee0d28c24aa2b2d1ec5398#diff-e7d2d77c4b01ac1a055eaa7b5bb2b8bb52cc3a04dc849130078104aa90602e49R716

The use of the C constant CL_EXPUNGE looks possibly wrong. That is the value provided by the c client library, not the PHP value. The flags parameter will have the PHP constant value 32768 and it is that which should be tested.

A few lines down the flags parameter is tested for PHP_EXPUNGE and then that bit is cleared.

	if (flags & PHP_EXPUNGE) {

https://github.com/php/php-src/commit/25569679aae88af948ee0d28c24aa2b2d1ec5398#diff-e7d2d77c4b01ac1a055eaa7b5bb2b8bb52cc3a04dc849130078104aa90602e49R728


Test script:
---------------
// can use any server because it doesn't get as far as connecting
$link = imap_open('{imap.gmail.com:993}INBOX', 'zzzxxxx', 'asasasasa', CL_EXPUNGE);


Expected result:
----------------
The mailbox should be opened and the program continue executing.

Actual result:
--------------
[Thu Feb 25 15:27:24.083079 2021] [php:error] [pid 22835] [client 127.0.0.1:33586] PHP Fatal error:  Uncaught ValueError: imap_open(): Argument #4 ($flags) must be a bitmask of the OP_* constants, and CL_EXPUNGE in /home/duncan/Development/GitHub/phplist3/public_html/lists/admin/processbounces.php:367
Stack trace:
#0 /home/duncan/Development/GitHub/phplist3/public_html/lists/admin/processbounces.php(367): imap_open()
#1 /home/duncan/Development/GitHub/phplist3/public_html/lists/admin/processbounces.php(497): processPop()
#2 /home/duncan/Development/GitHub/phplist3/public_html/lists/admin/index.php(752): include('...')
#3 {main}
  thrown in /home/duncan/Development/GitHub/phplist3/public_html/lists/admin/processbounces.php on line 367, referer: http://strontian/lists/admin/?page=bouncemgt&tk=6b1ba5b4ffee3a1a0d1d550a0290cd5f

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-25 15:52 UTC] nikic@php.net
-Assigned To: +Assigned To: girgias
 [2021-02-27 13:15 UTC] girgias@php.net
Automatic comment on behalf of girgias
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1ee6aad248117312fdc9ff7edc3ddd7bd5203d79
Log: Fix Bug #80800 imap_open() fails when the flags parameter includes CL_EXPUNGE
 [2021-02-27 13:15 UTC] girgias@php.net
-Status: Assigned +Status: Closed
 [2021-02-27 13:18 UTC] girgias@php.net
-Operating System: Linux Mint +Operating System: -PHP Version: 8.0.2 +PHP Version: 8.0.0
 [2021-02-27 13:18 UTC] girgias@php.net
Indeed the usage of CL_EXPUNGE was incorrect, this also affected imap_reopen().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC