]> granicus.if.org Git - php/commitdiff
Fix #64076: imap_sort() does not return FALSE on failure
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 13 Oct 2020 14:20:55 +0000 (16:20 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 13 Oct 2020 17:37:05 +0000 (19:37 +0200)
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.

NEWS
ext/imap/php_imap.c
ext/imap/tests/bug64076.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7e055893688b65faedbb612f9006fc96e426023f..fb966d9b7214ec8c5f7ec3c97fbe67471c77431b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
 
index a88c329b01dff1a232378c30512b28ecb0596a1f..db144b0d49fc37210527b1bfeb9ff9bc5a9ec9b0 100644 (file)
@@ -3181,6 +3181,9 @@ PHP_FUNCTION(imap_sort)
        } else {
                spg = mail_newsearchpgm();
        }
+       if (spg == NIL) {
+               RETURN_FALSE;
+       }
 
        mypgm = mail_newsortpgm();
        mypgm->reverse = rev;
diff --git a/ext/imap/tests/bug64076.phpt b/ext/imap/tests/bug64076.phpt
new file mode 100644 (file)
index 0000000..ccafcfe
--- /dev/null
@@ -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)