diff --git a/NEWS b/NEWS index a55214c7e01..45958625788 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,10 @@ PHP NEWS . Fixed bug GH-9155 (dba_open("non-existing", "c-", "flatfile") segfaults) (cmb) +- IMAP: + . Fixed bug GH-9309 (Segfault when connection is used after imap_close()). + (cmb) + - MBString: . Fixed bug GH-9008 (mb_detect_encoding(): wrong results with null $encodings). (cmb) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index a543c1d78a2..59244b664d7 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -198,7 +198,7 @@ static void imap_object_destroy(zend_object *zobj) { #define GET_IMAP_STREAM(imap_conn_struct, zval_imap_obj) \ imap_conn_struct = imap_object_from_zend_object(Z_OBJ_P(zval_imap_obj)); \ - if (!imap_conn_struct) { \ + if (imap_conn_struct->imap_stream == NULL) { \ zend_throw_exception(zend_ce_value_error, "IMAP\\Connection is already closed", 0); \ RETURN_THROWS(); \ } diff --git a/ext/imap/tests/gh9309.phpt b/ext/imap/tests/gh9309.phpt new file mode 100644 index 00000000000..663c6cc757f --- /dev/null +++ b/ext/imap/tests/gh9309.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug GH-9309 (Segfault when connection is used after imap_close()) +--EXTENSIONS-- +imap +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} +?> +--CLEAN-- + +--EXPECT-- +Create a temporary mailbox and add 0 msgs +New mailbox created +IMAP\Connection is already closed