|  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
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
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


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) {

Test script:
// can use any server because it doesn't get as far as connecting
$link = imap_open('{}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] 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-25 15:52 UTC]
-Assigned To: +Assigned To: girgias
 [2021-02-27 13:15 UTC]
Automatic comment on behalf of girgias
Log: Fix Bug #80800 imap_open() fails when the flags parameter includes CL_EXPUNGE
 [2021-02-27 13:15 UTC]
-Status: Assigned +Status: Closed
 [2021-02-27 13:18 UTC]
-Operating System: Linux Mint +Operating System: -PHP Version: 8.0.2 +PHP Version: 8.0.0
 [2021-02-27 13:18 UTC]
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: Tue Jul 23 18:01:30 2024 UTC