diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index f272e6d1741b..6998c3134a58 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -255,7 +255,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, /* remove the file created by php_stream_open_wrapper(), it is not needed since BZ2 functions * failed. */ - if (opened_path && !bz_file && mode[0] == 'w') { + if (opened_path && *opened_path && !bz_file && mode[0] == 'w') { VCWD_UNLINK(ZSTR_VAL(*opened_path)); } } diff --git a/ext/bz2/tests/dba_opened_path_null.phpt b/ext/bz2/tests/dba_opened_path_null.phpt new file mode 100644 index 000000000000..d73730a58dc8 --- /dev/null +++ b/ext/bz2/tests/dba_opened_path_null.phpt @@ -0,0 +1,16 @@ +--TEST-- +compress.bzip2:// opener must not unlink a NULL opened_path when the open fails +--EXTENSIONS-- +bz2 +dba +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: dba_open(%S): Failed to open stream: operation failed in %s on line %d +bool(false)