Skip to content

Commit

Permalink
Fix #64076: imap_sort() does not return FALSE on failure
Browse files Browse the repository at this point in the history
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 GH-6332.
  • Loading branch information
cmb69 committed Oct 13, 2020
1 parent 2d01a89 commit db8bf0a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.3.25

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

29 Oct 2020, PHP 7.3.24

Expand Down
3 changes: 3 additions & 0 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3181,6 +3181,9 @@ PHP_FUNCTION(imap_sort)
} else {
spg = mail_newsearchpgm();
}
if (spg == NIL) {
RETURN_FALSE;
}

mypgm = mail_newsortpgm();
mypgm->reverse = rev;
Expand Down
23 changes: 23 additions & 0 deletions ext/imap/tests/bug64076.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Bug #64076 (imap_sort() does not return FALSE on failure)
--SKIPIF--
<?php
require_once __DIR__ . '/skipif.inc';
?>
--FILE--
<?php
require_once __DIR__ . '/imap_include.inc';
$stream = setup_test_mailbox('', 2);
imap_errors(); // clear error stack
var_dump(imap_sort($stream, SORTFROM, 0, 0, 'UNSUPPORTED SEARCH CRITERIUM'));
var_dump(imap_errors() !== false);
?>
--CLEAN--
<?php
require_once __DIR__ . '/clean.inc';
?>
--EXPECT--
Create a temporary mailbox and add 2 msgs
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
bool(false)
bool(true)

0 comments on commit db8bf0a

Please sign in to comment.