[packages/php] Rel 2. Fix user wrapper bailout bugs
arekm
arekm at pld-linux.org
Fri Nov 20 08:13:39 CET 2026
commit 2ce07772d69692abfd1ee7a0e57bc6249c736168
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Fri Nov 20 08:06:52 2026 +0100
Rel 2. Fix user wrapper bailout bugs
SplFileObject freed a borrowed name after a bailout in a user wrapper.
php-spl-file-open-bailout.patch | 53 +++++++++++++++++++++++++++++++++++++++++
php.spec | 5 +++-
2 files changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index d5fa8be..ee3fd33 100644
--- a/php.spec
+++ b/php.spec
@@ -130,7 +130,7 @@
%define ver_suffix 86
%define php_suffix %{!?with_default_php:%{ver_suffix}}
%define subver %{nil}
-%define rel 1
+%define rel 2
Summary: PHP: Hypertext Preprocessor
Summary(fr.UTF-8): Le langage de script embarque-HTML PHP
Summary(pl.UTF-8): Język skryptowy PHP
@@ -189,6 +189,8 @@ Patch66: php-db.patch
Patch67: mysql-lib-ver-mismatch.patch
Patch71: libdb-info.patch
Patch72: opcache-revalidate-path-once.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch73: php-spl-file-open-bailout.patch
URL: https://www.php.net/
%{?with_pdo_firebird:%{!?with_interbase_inst:BuildRequires: Firebird-devel >= 3.0}}
BuildRequires: autoconf >= 2.68
@@ -1775,6 +1777,7 @@ cp -p php.ini-production php.ini
%patch -P67 -p1 -b .mysql-lib-ver-mismatch
%patch -P71 -p1 -b .libdb-info
%patch -P72 -p1
+%patch -P73 -p1
%{__sed} -i -e '1s,/usr/bin/env php,%{_bindir}/php,' \
ext/ext_skel.php \
diff --git a/php-spl-file-open-bailout.patch b/php-spl-file-open-bailout.patch
new file mode 100644
index 0000000..9ce625f
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,53 @@
+Subject: [PATCH] spl: own the SplFileObject file name before opening it
+
+spl_filesystem_file_open() kept the caller's file name without a reference
+until the open succeeded. A fatal error or a timeout inside a user stream
+wrapper's url_stat or stream_open left it there, and the object's free then
+released a reference it did not own: after SplFileInfo::openFile() the
+source object's name was released twice (use after free at shutdown).
+
+PLD-only: php-src (master too) still borrows the name until the open
+succeeds.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index c5dc56d4..2e767708 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -319,10 +319,14 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ zval tmp;
+
+ intern->type = SPL_FS_FILE;
++ /* file_name is borrowed from the caller; take a reference before user wrapper
++ * code can bail out, as spl_filesystem_object_free_storage() releases it */
++ intern->file_name = zend_string_copy(intern->file_name);
+ php_stat(intern->file_name, FS_IS_DIR, &tmp);
+ if (Z_TYPE(tmp) == IS_TRUE) {
+ zend_string_release(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
++ zend_string_release(intern->file_name);
+ intern->file_name = NULL;
+ zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories");
+ return FAILURE;
+@@ -337,7 +341,8 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ }
+ zend_string_release(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
+- intern->file_name = NULL; /* until here it is not a copy */
++ zend_string_release(intern->file_name);
++ intern->file_name = NULL;
+ return FAILURE;
+ }
+
+@@ -352,9 +357,9 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ */
+
+ if (ZSTR_LEN(intern->file_name) > 1 && IS_SLASH_AT(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1)) {
+- intern->file_name = zend_string_init(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1, 0);
+- } else {
+- intern->file_name = zend_string_copy(intern->file_name);
++ zend_string *file_name = zend_string_init(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1, 0);
++ zend_string_release(intern->file_name);
++ intern->file_name = file_name;
+ }
+
+ intern->orig_path = zend_string_init(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path), 0);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/2ce07772d69692abfd1ee7a0e57bc6249c736168
More information about the pld-cvs-commit
mailing list