Skip to content

Commit db8bf0a

Browse files
committed
Fix #64076: imap_sort() does not return FALSE on failure
If unsupported `$search_criteria` are passed to `imap_sort()`, the function returns an empty array, but there is also an error on the libc-client error stack ("Unknown search criterion: UNSUPPORTED (errflg=2)"). If, on the other hand, unsupported `$criteria` or unsupported `$flags` are passed, the function returns `false`. We solve this inconsistency by returning `false` for unsupported `$search_criteria` as well. Closes phpGH-6332.
1 parent 2d01a89 commit db8bf0a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.25
44

5+
- IMAP:
6+
. Fixed bug #64076 (imap_sort() does not return FALSE on failure). (cmb)
57

68
29 Oct 2020, PHP 7.3.24
79

ext/imap/php_imap.c

+3
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,9 @@ PHP_FUNCTION(imap_sort)
31813181
} else {
31823182
spg = mail_newsearchpgm();
31833183
}
3184+
if (spg == NIL) {
3185+
RETURN_FALSE;
3186+
}
31843187

31853188
mypgm = mail_newsortpgm();
31863189
mypgm->reverse = rev;

ext/imap/tests/bug64076.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #64076 (imap_sort() does not return FALSE on failure)
3+
--SKIPIF--
4+
<?php
5+
require_once __DIR__ . '/skipif.inc';
6+
?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . '/imap_include.inc';
10+
$stream = setup_test_mailbox('', 2);
11+
imap_errors(); // clear error stack
12+
var_dump(imap_sort($stream, SORTFROM, 0, 0, 'UNSUPPORTED SEARCH CRITERIUM'));
13+
var_dump(imap_errors() !== false);
14+
?>
15+
--CLEAN--
16+
<?php
17+
require_once __DIR__ . '/clean.inc';
18+
?>
19+
--EXPECT--
20+
Create a temporary mailbox and add 2 msgs
21+
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
22+
bool(false)
23+
bool(true)

0 commit comments

Comments
 (0)