[php-src] master: Merge branch 'PHP-8.6'

From: Date: Sun, 22 Nov 2026 16:16:22 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144036@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-23T00:11:18+08:00 Commit: https://github.com/php/php-src/commit/97adf31cc228bc90a8dbbdeacf629da800235e85 Raw diff: https://github.com/php/php-src/commit/97adf31cc228bc90a8dbbdeacf629da800235e85.diff Merge branch 'PHP-8.6' * PHP-8.6: Fix GH-25528: Retain the Phar OpenSSL signing key (#25529) Changed paths: A ext/phar/tests/phar_setsignaturealgo_openssl_key_copy.phpt M ext/phar/phar.c M ext/phar/phar_internal.h M ext/phar/phar_object.c M ext/phar/util.c Diff: diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 53691bea587a..b6b4787daa3b 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -3460,6 +3460,11 @@ PHP_RSHUTDOWN_FUNCTION(phar) /* {{{ */ PHAR_G(cwd_init) = 0; } + if (PHAR_G(openssl_privatekey)) { + zend_string_release(PHAR_G(openssl_privatekey)); + PHAR_G(openssl_privatekey) = NULL; + } + PHAR_G(request_done) = 1; return SUCCESS; } diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 7047d10a6c7d..0eaa65942ccb 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -144,8 +144,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phar) char* cwd; uint32_t cwd_len; bool cwd_init; - char *openssl_privatekey; - uint32_t openssl_privatekey_len; + zend_string *openssl_privatekey; /* phar_get_archive cache */ const zend_string *last_phar_name; uint32_t last_alias_len; diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 20562aafc782..5bf919c13bdd 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -2989,10 +2989,10 @@ PHP_METHOD(Phar, setDefaultStub) PHP_METHOD(Phar, setSignatureAlgorithm) { zend_long algo; - char *error, *key = NULL; - size_t key_len = 0; + char *error; + zend_string *key = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!", &algo, &key, &key_len) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|S!", &algo, &key) != SUCCESS) { RETURN_THROWS(); } @@ -3018,8 +3018,10 @@ PHP_METHOD(Phar, setSignatureAlgorithm) } phar_obj->archive->sig_flags = (uint32_t)algo; phar_obj->archive->is_modified = 1; - PHAR_G(openssl_privatekey) = key; - PHAR_G(openssl_privatekey_len) = key_len; + if (PHAR_G(openssl_privatekey)) { + zend_string_release(PHAR_G(openssl_privatekey)); + } + PHAR_G(openssl_privatekey) = key ? zend_string_copy(key) : NULL; phar_flush(phar_obj->archive, &error); if (error) { diff --git a/ext/phar/tests/phar_setsignaturealgo_openssl_key_copy.phpt b/ext/phar/tests/phar_setsignaturealgo_openssl_key_copy.phpt new file mode 100644 index 000000000000..b9e0265d21c6 --- /dev/null +++ b/ext/phar/tests/phar_setsignaturealgo_openssl_key_copy.phpt @@ -0,0 +1,33 @@ +--TEST-- +Phar::setSignatureAlgorithm() with Phar::OPENSSL keeps its own copy of the private key +--EXTENSIONS-- +phar +openssl +--SKIPIF-- +<?php +if (!in_array("OpenSSL", Phar::getSupportedSignatures())) die("skip openssl support required"); +?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar'; +$keyfile = __DIR__ . '/files/private.pem'; + +$p = new Phar($fname); +$p['file1.txt'] = 'hi'; +// The key string is freed when the call returns +$p->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents($keyfile)); +// Reuse the freed memory +$other = str_repeat('x', filesize($keyfile)); +// Signs the phar again +$p['file2.txt'] = 'hello'; +var_dump($p->getSignature()['hash_type']); +?> +--CLEAN-- +<?php +unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); +?> +--EXPECT-- +string(7) "OpenSSL" diff --git a/ext/phar/util.c b/ext/phar/util.c index f0964ff26759..c6d859ec631c 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -1890,7 +1890,7 @@ ZEND_ATTRIBUTE_NONNULL zend_string* phar_create_signature(phar_archive_data *pha mdtype = EVP_sha1(); } - in = BIO_new_mem_buf(PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len)); + in = PHAR_G(openssl_privatekey) ? BIO_new_mem_buf(ZSTR_VAL(PHAR_G(openssl_privatekey)), (int) ZSTR_LEN(PHAR_G(openssl_privatekey))) : NULL; if (in == NULL) { spprintf(error, 0, "unable to write to phar \"%s\" with requested openssl signature", ZSTR_VAL(phar->fname)); @@ -1952,7 +1952,8 @@ ZEND_ATTRIBUTE_NONNULL zend_string* phar_create_signature(phar_archive_data *pha siglen = 0; php_stream_seek(fp, 0, SEEK_END); - if (FAILURE == phar_call_openssl_sign(fp, php_stream_tell(fp), PHAR_G(openssl_privatekey), PHAR_G(openssl_privatekey_len), (char **)&sigbuf, &siglen, phar->sig_flags)) { + zend_string *privatekey = PHAR_G(openssl_privatekey); + if (FAILURE == phar_call_openssl_sign(fp, php_stream_tell(fp), privatekey ? ZSTR_VAL(privatekey) : NULL, privatekey ? ZSTR_LEN(privatekey) : 0, (char **)&sigbuf, &siglen, phar->sig_flags)) { spprintf(error, 0, "unable to write phar \"%s\" with requested openssl signature", ZSTR_VAL(phar->fname)); return NULL; }

« previous php.cvs (#144036) next »