Commit 567509d2773 for php

commit 567509d277306503d9178fd4381b9169fdaad127
Author: Gina Peter Banyard <girgias@php.net>
Date:   Fri Nov 20 15:22:13 2026 +0000

    tree: use %pS format specifier when possible in stream error functions (#25453)

diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 21feb034817..91521c72930 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -347,16 +347,17 @@ static int php_openssl_handle_ssl_error(php_stream *stream, int nr_bytes, bool i
 						smart_str_appends(&ebuf, esbuf);
 					} while ((ecode = ERR_get_error()) != 0);

-					smart_str_0(&ebuf);
-
-					php_stream_warn(stream, ProtocolError,
-							"SSL operation failed with code %d. %s%s",
-							err,
-							ebuf.s ? "OpenSSL Error messages:\n" : "",
-							ebuf.s ? ZSTR_VAL(ebuf.s) : "");
-					if (ebuf.s) {
-						smart_str_free(&ebuf);
+					zend_string *openssl_error = smart_str_extract(&ebuf);
+					if (ZSTR_LEN(openssl_error) == 0) {
+						php_stream_warn(stream, ProtocolError,
+								"SSL operation failed with code %d.",
+								err);
+					} else {
+						php_stream_warn(stream, ProtocolError,
+								"SSL operation failed with code %d. OpenSSL Error messages:\n%pS",
+								err, openssl_error);
 					}
+					zend_string_release_ex(openssl_error, false);
 			}

 			retry = false;
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c
index 27f665fc349..0b0663bae2d 100644
--- a/ext/standard/ftp_fopen_wrapper.c
+++ b/ext/standard/ftp_fopen_wrapper.c
@@ -270,7 +270,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
 		zend_string *user = php_ftp_url_decode(resource->user);

 		if (php_ftp_has_cntrl(user)) {
-			php_stream_wrapper_log_warn(wrapper, context, options, AuthFailed, "Invalid login %s", ZSTR_VAL(user));
+			php_stream_wrapper_log_warn(wrapper, context, options, AuthFailed, "Invalid login %pS", user);
 			zend_string_efree(user);
 			goto connect_errexit;
 		}
@@ -292,7 +292,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
 			zend_string *password = php_ftp_url_decode(resource->password);

 			if (php_ftp_has_cntrl(password)) {
-				php_stream_wrapper_log_warn(wrapper, context, options, AuthFailed, "Invalid password %s", ZSTR_VAL(password));
+				php_stream_wrapper_log_warn(wrapper, context, options, AuthFailed, "Invalid password %pS", password);
 				zend_string_efree(password);
 				goto connect_errexit;
 			}
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index 35d5fe01322..cdfb971f81f 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -571,7 +571,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,

 	if (errstr) {
 		php_stream_wrapper_log_warn(wrapper, context, options, ProtocolError,
-			"%s", ZSTR_VAL(errstr));
+			"%pS", errstr);
 		zend_string_release_ex(errstr, 0);
 		errstr = NULL;
 	}
diff --git a/main/streams/userspace.c b/main/streams/userspace.c
index 44043fda314..77047585bea 100644
--- a/main/streams/userspace.c
+++ b/main/streams/userspace.c
@@ -331,8 +331,8 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
 	zval_ptr_dtor(&args[0]);

 	if (UNEXPECTED(call_result == FAILURE)) {
-		php_stream_wrapper_log_warn(wrapper, context, options,NotImplemented,
-				"\"%s::" USERSTREAM_OPEN "\" is not implemented", ZSTR_VAL(us->wrapper->ce->name));
+		php_stream_wrapper_log_warn(wrapper, context, options, NotImplemented,
+				"\"%pS::" USERSTREAM_OPEN "\" is not implemented", us->wrapper->ce->name);
 		zval_ptr_dtor(&args[3]);
 		goto end;
 	}
@@ -356,7 +356,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
 	} else {
 		php_stream_wrapper_log_warn(wrapper, context, options,
 				UserspaceCallFailed,
-				"\"%s::" USERSTREAM_OPEN "\" call failed", ZSTR_VAL(us->wrapper->ce->name));
+				"\"%pS::" USERSTREAM_OPEN "\" call failed", us->wrapper->ce->name);
 	}

 	zval_ptr_dtor(&zretval);
@@ -421,8 +421,8 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_log_warn(wrapper, context, options, NotImplemented,
-				"\"%s::" USERSTREAM_DIR_OPEN "\" is not implemented",
-				ZSTR_VAL(us->wrapper->ce->name));
+				"\"%pS::" USERSTREAM_DIR_OPEN "\" is not implemented",
+				us->wrapper->ce->name);
 		goto end;
 	}
 	/* Exception occurred in call */
@@ -439,7 +439,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
 	} else {
 		php_stream_wrapper_log_warn(wrapper, context, options,
 				UserspaceCallFailed,
-				"\"%s::" USERSTREAM_DIR_OPEN "\" call failed", ZSTR_VAL(us->wrapper->ce->name));
+				"\"%pS::" USERSTREAM_DIR_OPEN "\" call failed", us->wrapper->ce->name);
 	}
 	zval_ptr_dtor(&zretval);

@@ -491,13 +491,13 @@ PHP_FUNCTION(stream_wrapper_register)
 	if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) {
 		php_stream_wrapper_warn(&uwrap->wrapper, NULL, REPORT_ERRORS,
 				WrapperRegistrationFailed,
-				"Protocol %s:// is already defined.", ZSTR_VAL(protocol));
+				"Protocol %pS:// is already defined.", protocol);
 	} else {
 		/* Hash doesn't exist so it must have been an invalid protocol scheme */
 		php_stream_wrapper_warn(&uwrap->wrapper, NULL, REPORT_ERRORS,
 				WrapperRegistrationFailed,
-				"Invalid protocol scheme specified. Unable to register wrapper class %s to %s://",
-				ZSTR_VAL(uwrap->ce->name), ZSTR_VAL(protocol));
+				"Invalid protocol scheme specified. Unable to register wrapper class %pS to %pS://",
+				uwrap->ce->name, protocol);
 	}

 	zend_list_delete(rsrc);
@@ -519,7 +519,7 @@ PHP_FUNCTION(stream_wrapper_unregister)
 		/* We failed */
 		php_stream_wrapper_warn(wrapper, NULL, REPORT_ERRORS,
 				WrapperUnregistrationFailed,
-				"Unable to unregister protocol %s://", ZSTR_VAL(protocol));
+				"Unable to unregister protocol %pS://", protocol);
 		RETURN_FALSE;
 	}

@@ -549,7 +549,7 @@ PHP_FUNCTION(stream_wrapper_restore)
 	if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, NULL, REPORT_ERRORS,
 				WrapperNotFound,
-				"%s:// never existed, nothing to restore", ZSTR_VAL(protocol));
+				"%pS:// never existed, nothing to restore", protocol);
 		RETURN_FALSE;
 	}

@@ -557,7 +557,7 @@ PHP_FUNCTION(stream_wrapper_restore)
 	if (wrapper_hash == global_wrapper_hash || zend_hash_find_ptr(wrapper_hash, protocol) == wrapper) {
 		php_stream_wrapper_notice(wrapper, NULL, REPORT_ERRORS,
 				WrapperRestorationFailed,
-				"%s:// was never changed, nothing to restore", ZSTR_VAL(protocol));
+				"%pS:// was never changed, nothing to restore", protocol);
 		RETURN_TRUE;
 	}

@@ -567,7 +567,7 @@ PHP_FUNCTION(stream_wrapper_restore)
 	if (php_register_url_stream_wrapper_volatile(protocol, wrapper) == FAILURE) {
 		php_stream_wrapper_warn(wrapper, NULL, REPORT_ERRORS,
 			WrapperRestorationFailed,
-			"Unable to restore original %s:// wrapper", ZSTR_VAL(protocol));
+			"Unable to restore original %pS:// wrapper", protocol);
 		RETURN_FALSE;
 	}

@@ -596,7 +596,7 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_WRITE " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_WRITE " is not implemented!", us->wrapper->ce->name);
 	}

 	stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
@@ -617,9 +617,9 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
 	/* don't allow strange buffer overruns due to bogus return */
 	if (didwrite > 0 && didwrite > count) {
 		php_stream_warn_nt(stream, UserspaceInvalidReturn,
-				"%s::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested ("
+				"%pS::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested ("
 						ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max)",
-				ZSTR_VAL(us->wrapper->ce->name),
+				us->wrapper->ce->name,
 				(zend_long)(didwrite - count), (zend_long)didwrite, (zend_long)count);
 		didwrite = count;
 	}
@@ -650,7 +650,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_READ " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_READ " is not implemented!", us->wrapper->ce->name);
 		goto err;
 	}

@@ -667,10 +667,10 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
 	if (didread > 0) {
 		if (didread > count) {
 			php_stream_warn_nt(stream, UserspaceInvalidReturn,
-					"%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT
+					"%pS::" USERSTREAM_READ " - read " ZEND_LONG_FMT
 							" bytes more data than requested (" ZEND_LONG_FMT " read, "
 							ZEND_LONG_FMT " max) - excess data will be lost",
-					ZSTR_VAL(us->wrapper->ce->name), (zend_long)(didread - count),
+					us->wrapper->ce->name, (zend_long)(didread - count),
 					(zend_long)didread, (zend_long)count);
 			didread = count;
 		}
@@ -688,8 +688,8 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
-				ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_EOF " is not implemented! Assuming EOF",
+				us->wrapper->ce->name);
 		stream->eof = 1;
 		goto err;
 	}
@@ -804,7 +804,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
 		ret = 0;
 	} else if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_TELL " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_TELL " is not implemented!", us->wrapper->ce->name);
 		ret = -1;
 	} else {
 		ret = -1;
@@ -869,7 +869,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_STAT " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_STAT " is not implemented!", us->wrapper->ce->name);
 		return -1;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -897,8 +897,8 @@ static int user_stream_set_check_liveliness(php_stream *stream, const php_userst

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF",
-				ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_EOF " is not implemented! Assuming EOF",
+				us->wrapper->ce->name);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -908,8 +908,8 @@ static int user_stream_set_check_liveliness(php_stream *stream, const php_userst
 		return Z_TYPE(retval) == IS_TRUE ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK;
 	} else {
 		php_stream_warn(stream, UserspaceInvalidReturn,
-				"%s::" USERSTREAM_EOF " value must be of type bool, %s given",
-				ZSTR_VAL(us->wrapper->ce->name), zend_zval_value_name(&retval));
+				"%pS::" USERSTREAM_EOF " value must be of type bool, %s given",
+				us->wrapper->ce->name, zend_zval_value_name(&retval));
 		zval_ptr_dtor(&retval);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
@@ -951,7 +951,7 @@ static int user_stream_set_locking(php_stream *stream, const php_userstream_data
 			return PHP_STREAM_OPTION_RETURN_OK;
 		}
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_LOCK " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_LOCK " is not implemented!", us->wrapper->ce->name);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -964,8 +964,8 @@ static int user_stream_set_locking(php_stream *stream, const php_userstream_data
 	// TODO: ext/standard/tests/file/userstreams_004.phpt returns null implicitly for function
 	// Should this warn or not? And should this be considered an error?
 	//php_stream_warn(stream, UserspaceInvalidReturn,
-	//		"%s::" USERSTREAM_LOCK " value must be of type bool, %s given",
-	//		ZSTR_VAL(us->wrapper->ce->name), zend_zval_value_name(&retval));
+	//		"%pS::" USERSTREAM_LOCK " value must be of type bool, %s given",
+	//		us->wrapper->ce->name, zend_zval_value_name(&retval));
 	zval_ptr_dtor(&retval);
 	return PHP_STREAM_OPTION_RETURN_NOTIMPL;
 }
@@ -1000,7 +1000,7 @@ static int user_stream_set_truncation(php_stream *stream, const php_userstream_d

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_TRUNCATE " is not implemented!", ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_TRUNCATE " is not implemented!", us->wrapper->ce->name);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -1010,8 +1010,8 @@ static int user_stream_set_truncation(php_stream *stream, const php_userstream_d
 		return Z_TYPE(retval) == IS_TRUE ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
 	} else {
 		php_stream_warn(stream, UserspaceInvalidReturn,
-				"%s::" USERSTREAM_TRUNCATE " value must be of type bool, %s given",
-				ZSTR_VAL(us->wrapper->ce->name), zend_zval_value_name(&retval));
+				"%pS::" USERSTREAM_TRUNCATE " value must be of type bool, %s given",
+				us->wrapper->ce->name, zend_zval_value_name(&retval));
 		zval_ptr_dtor(&retval);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
@@ -1044,8 +1044,8 @@ static int user_stream_set_option(php_stream *stream, const php_userstream_data_

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-				"%s::" USERSTREAM_SET_OPTION " is not implemented!",
-				ZSTR_VAL(us->wrapper->ce->name));
+				"%pS::" USERSTREAM_SET_OPTION " is not implemented!",
+				us->wrapper->ce->name);
 		return PHP_STREAM_OPTION_RETURN_ERR;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -1114,7 +1114,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-				"%s::" USERSTREAM_UNLINK " is not implemented!", ZSTR_VAL(ce->name));
+				"%pS::" USERSTREAM_UNLINK " is not implemented!", ce->name);
 	} else if (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE) {
 		ret = Z_TYPE(zretval) == IS_TRUE;
 	}
@@ -1153,7 +1153,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-				"%s::" USERSTREAM_RENAME " is not implemented!", ZSTR_VAL(ce->name));
+				"%pS::" USERSTREAM_RENAME " is not implemented!", ce->name);
 	} else if (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE) {
 		ret = Z_TYPE(zretval) == IS_TRUE;
 	}
@@ -1192,7 +1192,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-				"%s::" USERSTREAM_MKDIR " is not implemented!", ZSTR_VAL(ce->name));
+				"%pS::" USERSTREAM_MKDIR " is not implemented!", ce->name);
 	} else if (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE) {
 		ret = Z_TYPE(zretval) == IS_TRUE;
 	}
@@ -1230,7 +1230,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-				"%s::" USERSTREAM_RMDIR " is not implemented!", ZSTR_VAL(ce->name));
+				"%pS::" USERSTREAM_RMDIR " is not implemented!", ce->name);
 	} else if (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE) {
 		ret = Z_TYPE(zretval) == IS_TRUE;
 	}
@@ -1295,7 +1295,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-				"%s::" USERSTREAM_METADATA " is not implemented!", ZSTR_VAL(ce->name));
+				"%pS::" USERSTREAM_METADATA " is not implemented!", ce->name);
 	} else if (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE) {
 		ret = Z_TYPE(zretval) == IS_TRUE;
 	}
@@ -1334,7 +1334,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_wrapper_warn_name(user_stream_wops.label, context, REPORT_ERRORS, NotImplemented,
-			"%s::" USERSTREAM_STATURL " is not implemented!", ZSTR_VAL(ce->name));
+			"%pS::" USERSTREAM_STATURL " is not implemented!", ce->name);
 		return -1;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(zretval))) {
@@ -1370,8 +1370,8 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co

 	if (UNEXPECTED(call_result == FAILURE)) {
 		php_stream_warn(stream, NotImplemented,
-			"%s::" USERSTREAM_DIR_READ " is not implemented!",
-			ZSTR_VAL(us->wrapper->ce->name));
+			"%pS::" USERSTREAM_DIR_READ " is not implemented!",
+			us->wrapper->ce->name);
 		return -1;
 	}
 	if (UNEXPECTED(Z_ISUNDEF(retval))) {
@@ -1459,8 +1459,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
 	if (UNEXPECTED(call_result == FAILURE)) {
 		if (report_errors) {
 			php_stream_warn(stream, NotImplemented,
-					"%s::" USERSTREAM_CAST " is not implemented!",
-					ZSTR_VAL(us->wrapper->ce->name));
+					"%pS::" USERSTREAM_CAST " is not implemented!",
+					us->wrapper->ce->name);
 		}
 		goto out;
 	}
@@ -1474,16 +1474,16 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
 		if (!intstream) {
 			if (report_errors) {
 				php_stream_warn(stream, UserspaceInvalidReturn,
-						"%s::" USERSTREAM_CAST " must return a stream resource",
-						ZSTR_VAL(us->wrapper->ce->name));
+						"%pS::" USERSTREAM_CAST " must return a stream resource",
+						us->wrapper->ce->name);
 			}
 			break;
 		}
 		if (intstream == stream) {
 			if (report_errors) {
 				php_stream_warn(stream, UserspaceInvalidReturn,
-						"%s::" USERSTREAM_CAST " must not return itself",
-						ZSTR_VAL(us->wrapper->ce->name));
+						"%pS::" USERSTREAM_CAST " must not return itself",
+						us->wrapper->ce->name);
 			}
 			intstream = NULL;
 			break;