From 0076b47326e53d98b5df56c5f970b2b5cc3d9b6d Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 30 Nov 2020 04:48:17 +0000 Subject: [PATCH] Fix Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0 Checking for a valid Unique ID (UID) cannot use the convenience macro as they might be larger than the message number which has for maximum value the total number of current messages available in the mailbox. --- NEWS | 3 ++ ext/imap/php_imap.c | 12 ++++-- ext/imap/tests/bug80438.phpt | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 ext/imap/tests/bug80438.phpt diff --git a/NEWS b/NEWS index 7fc6ff6131..f7c3861100 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ PHP NEWS - Fileinfo: . Fixed bug #77961 (finfo_open crafted magic parsing SIGABRT). (cmb) +- IMAP + . Fixed bug #80438 (imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0). (girgias) + - Intl: . Fixed bug #80425 (MessageFormatAdapter::getArgTypeList redefined). (Nikita) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index c561a5e72c..023795fd8c 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -2835,10 +2835,10 @@ PHP_FUNCTION(imap_uid) PHP_FUNCTION(imap_msgno) { zval *streamind; - zend_long msgno; + zend_long msg_uid; pils *imap_le_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msgno) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msg_uid) == FAILURE) { RETURN_THROWS(); } @@ -2846,9 +2846,13 @@ PHP_FUNCTION(imap_msgno) RETURN_THROWS(); } - PHP_IMAP_CHECK_MSGNO(msgno, 2); + /* Do NOT use the PHP_IMAP_CHECK_MSGNO() macro as UID cannot be checked for their upper bound. */ + if (msg_uid < 1) { + zend_argument_value_error(2, "must be greater than 0"); + RETURN_THROWS(); + } - RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msgno)); + RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msg_uid)); } /* }}} */ diff --git a/ext/imap/tests/bug80438.phpt b/ext/imap/tests/bug80438.phpt new file mode 100644 index 0000000000..ea35f01a7b --- /dev/null +++ b/ext/imap/tests/bug80438.phpt @@ -0,0 +1,72 @@ +--TEST-- +Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0 +--SKIPIF-- + +--FILE-- + +--CLEAN-- + +--EXPECT-- +*** Testing imap_fetch_overview() : basic functionality *** +Create a temporary mailbox and add 10 msgs +New mailbox created +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(9) + [5]=> + int(10) +} +Unique ID: int(1) +Ordered message number: int(1) +Unique ID: int(2) +Ordered message number: int(2) +Unique ID: int(3) +Ordered message number: int(3) +Unique ID: int(4) +Ordered message number: int(4) +Unique ID: int(9) +Ordered message number: int(5) +Unique ID: int(10) +Ordered message number: int(6) -- 2.40.0