[packages/php/PHP_5_2] Rel 54. Fix user wrapper bailout bugs

arekm arekm at pld-linux.org
Fri Nov 20 08:15:20 CET 2026


commit df55b9e4981c84513971168b6d693d001396da92
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Fri Nov 20 08:06:53 2026 +0100

    Rel 54. 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      | 54 ++++++++++++++++++++++++++++++++++++
 php-user-stream-filename-reset.patch | 24 ++++++++++++++++
 php.spec                             |  7 ++++-
 3 files changed, 84 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 41a6b87..4cf0cd1 100644
--- a/php.spec
+++ b/php.spec
@@ -112,7 +112,7 @@ ERROR: You need to select at least one Apache SAPI to build shared modules.
 %define		magic_mime	/usr/share/misc/magic.mime
 %endif
 
-%define		rel	53
+%define		rel	54
 %define		orgname	php
 %define		ver_suffix 52
 %define		php_suffix %{!?with_default_php:%{ver_suffix}}
@@ -247,6 +247,9 @@ Patch97:	CVE-2026-126714.patch
 Patch98:	CVE-2026-128064.patch
 Patch99:	CVE-2026-127960.patch
 Patch101:	CVE-2026-129481.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch102:	php-spl-file-open-bailout.patch
+Patch103:	php-user-stream-filename-reset.patch
 # CENTALT patches
 # Backport from 5.3.6
 Patch311:	php-5.3.6-bug-47435.patch
@@ -2034,6 +2037,8 @@ done
 %patch -P98 -p1
 %patch -P99 -p1
 %patch -P101 -p1
+%patch -P102 -p1
+%patch -P103 -p1
 
 # security-backports.patch changes only the .re scanner sources, and the
 # Makefiles have regeneration rules for just two of these four
diff --git a/php-spl-file-open-bailout.patch b/php-spl-file-open-bailout.patch
new file mode 100644
index 0000000..f98a9ea
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,54 @@
+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 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, remicollet/php-src-security and
+Debian/Freexian php5 and php7.0 have no fix.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index a1f8309..1b6b013 100755
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -202,6 +202,12 @@ static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TS
+ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent TSRMLS_DC) /* {{{ */
+ {
+ 	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);
++
+ 	intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0);
+ 	intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, intern->u.file.context);
+ 
+@@ -209,7 +215,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 TSRMLS_CC, "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;
+ 	}
+@@ -223,12 +231,9 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ 	  ||intern->file_name[intern->file_name_len-1] == '\\'
+ #endif
+ 	) {
+-		intern->file_name_len--;
++		intern->file_name[--intern->file_name_len] = '\0';
+ 	}
+ 
+-	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_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream));
+ 	intern->u.file.zresource.refcount = 1;
diff --git a/php-user-stream-filename-reset.patch b/php-user-stream-filename-reset.patch
new file mode 100644
index 0000000..d6eacf7
--- /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 35af521..a26f280 100755
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1441,6 +1441,7 @@ static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC
+ 
+ void php_shutdown_stream_hashes(TSRMLS_D)
+ {
++	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/df55b9e4981c84513971168b6d693d001396da92



More information about the pld-cvs-commit mailing list