[packages/php/PHP_7_3] Rel 24. Fix user wrapper bailout bugs

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


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

    Rel 24. 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 ee660c6..e41a28b 100644
--- a/php.spec
+++ b/php.spec
@@ -155,7 +155,7 @@ Summary(ru.UTF-8):	PHP Версии 7 - язык препроцессирова
 Summary(uk.UTF-8):	PHP Версії 7 - мова препроцесування HTML-файлів, виконувана на сервері
 Name:		%{orgname}%{php_suffix}
 Version:	7.3.33
-Release:	23
+Release:	24
 Epoch:		4
 # All files licensed under PHP version 3.01, except
 # Zend is licensed under Zend
@@ -356,6 +356,9 @@ Patch338:	php-bug80763.patch
 Patch339:	php-bug80889.patch
 Patch340:	php-bug80915.patch
 Patch341:	php-gh18953.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch342:	php-spl-file-open-bailout.patch
+Patch343:	php-user-stream-filename-reset.patch
 URL:		https://www.php.net/
 %{?with_interbase:%{!?with_interbase_inst:BuildRequires:	Firebird-devel >= 1.0.2.908-2}}
 %{?with_pspell:BuildRequires:	aspell-devel >= 2:0.50.0}
@@ -2305,6 +2308,8 @@ cp -p php.ini-production php.ini
 %patch -P339 -p1
 %patch -P340 -p1
 %patch -P341 -p1
+%patch -P342 -p1
+%patch -P343 -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..9d17e86
--- /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 6e79bc40..62f65625 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..d13f81c
--- /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 955753da..c6888e37 100644
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1614,6 +1614,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/3ac23e56fa9a9997e5828419f50d3dcd757ffb7b



More information about the pld-cvs-commit mailing list