[packages/php/PHP_7_4] Rel 21. Fix user wrapper bailout bugs
arekm
arekm at pld-linux.org
Fri Nov 20 08:14:35 CET 2026
commit 47a0d3eb6c4abe216a3dc733dcb8c60c3f90a94a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Fri Nov 20 08:06:52 2026 +0100
Rel 21. Fix user wrapper bailout bugs
SplFileObject freed a borrowed name after a bailout in a user wrapper.
User wrapper recursion guard outlived a bailout into the next request.
php-spl-file-open-bailout.patch | 60 ++++++++++++++++++++++++++++++++++++
php-user-stream-filename-reset.patch | 24 +++++++++++++++
php.spec | 7 ++++-
3 files changed, 90 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 5b1d01b..41138c3 100644
--- a/php.spec
+++ b/php.spec
@@ -150,7 +150,7 @@ Summary(ru.UTF-8): PHP Версии 7 - язык препроцессирова
Summary(uk.UTF-8): PHP Версії 7 - мова препроцесування HTML-файлів, виконувана на сервері
Name: %{orgname}%{php_suffix}
Version: 7.4.33
-Release: 20
+Release: 21
Epoch: 4
# All files licensed under PHP version 3.01, except
# Zend is licensed under Zend
@@ -285,6 +285,9 @@ Patch260: php-cve-2026-129481.patch
Patch300: php-c99-configure.patch
Patch301: php-bug66049.patch
Patch302: php-gh18953.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch303: php-spl-file-open-bailout.patch
+Patch304: php-user-stream-filename-reset.patch
URL: https://www.php.net/
%{?with_pdo_firebird:%{!?with_interbase_inst:BuildRequires: Firebird-devel >= 1.0.2.908-2}}
%{?with_pspell:BuildRequires: aspell-devel >= 2:0.50.0}
@@ -2076,6 +2079,8 @@ cp -p php.ini-production php.ini
%patch -P300 -p1
%patch -P301 -p1
%patch -P302 -p1
+%patch -P303 -p1
+%patch -P304 -p1
sed -E -i -e '1s,#!\s*/usr/bin/env\s+(.*),#!%{__bindir}\1,' \
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..e79e198
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,60 @@
+Subject: [PATCH] spl: own the SplFileObject file name before opening it
+
+spl_filesystem_file_open() kept pointing at the caller's file name until the
+open succeeded. exit(), 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 an interned literal or another SplFileInfo's name (invalid or
+double free at shutdown).
+
+PLD-only: php-src (master too) still borrows the name until the open
+succeeds; shivammathur/php-src-backports and remicollet/php-src-security
+have no fix.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index 202a815e..c00a1881 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -288,9 +288,16 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+
+ intern->type = SPL_FS_FILE;
+
++ /* both are borrowed from the caller; copy them before user wrapper code can
++ * bail out, as spl_filesystem_object_free_storage() frees file_name */
++ intern->file_name = estrndup(intern->file_name, intern->file_name_len);
++ intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
++
+ php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp);
+ if (Z_TYPE(tmp) == IS_TRUE) {
++ efree(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
++ efree(intern->file_name);
+ intern->file_name = NULL;
+ zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories");
+ return FAILURE;
+@@ -303,7 +310,9 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ if (!EG(exception)) {
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
+ }
+- intern->file_name = NULL; /* until here it is not a copy */
++ efree(intern->file_name);
++ intern->file_name = NULL;
++ efree(intern->u.file.open_mode);
+ intern->u.file.open_mode = NULL;
+ return FAILURE;
+ }
+@@ -316,14 +325,11 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ */
+
+ if (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
+- intern->file_name_len--;
++ intern->file_name[--intern->file_name_len] = '\0';
+ }
+
+ intern->orig_path = estrndup(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path));
+
+- intern->file_name = estrndup(intern->file_name, intern->file_name_len);
+- intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
+-
+ /* avoid reference counting in debug mode, thus do it manually */
+ ZVAL_RES(&intern->u.file.zresource, intern->u.file.stream->res);
+ /*!!! TODO: maybe bug?
diff --git a/php-user-stream-filename-reset.patch b/php-user-stream-filename-reset.patch
new file mode 100644
index 0000000..a330b26
--- /dev/null
+++ b/php-user-stream-filename-reset.patch
@@ -0,0 +1,24 @@
+From d0b3096ff0f6f6f491833858f126a80f18b81151 Mon Sep 17 00:00:00 2001
+From: Dmitry Stogov <dmitry at zend.com>
+Date: Mon, 12 Sep 2022 11:38:31 +0300
+Subject: [PATCH] Reset FG(user_stream_current_filename) at the end of request
+
+A bailout inside a user stream wrapper's stream_open or dir_opendir left
+the recursion guard pointing into the finished request, so a later request
+of the same process could read freed memory and fail with "infinite
+recursion prevented" when it opened the same URL.
+
+Origin: upstream, https://github.com/php/php-src/commit/d0b3096ff0f6f6f491833858f126a80f18b81151
+---
+diff --git a/main/streams/streams.c b/main/streams/streams.c
+index 8f368d4a..fe6ed878 100644
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1691,6 +1691,7 @@ static void stream_resource_persistent_dtor(zend_resource *rsrc)
+
+ void php_shutdown_stream_hashes(void)
+ {
++ FG(user_stream_current_filename) = NULL;
+ if (FG(stream_wrappers)) {
+ zend_hash_destroy(FG(stream_wrappers));
+ efree(FG(stream_wrappers));
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/47a0d3eb6c4abe216a3dc733dcb8c60c3f90a94a
More information about the pld-cvs-commit
mailing list