Skip to content

ext/openssl: Defer pkcs7/cms verify output writes until verification succeeds - #23651

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/openssl-ss004-pre-verify-truncation
Open

ext/openssl: Defer pkcs7/cms verify output writes until verification succeeds#23651
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/openssl-ss004-pre-verify-truncation

Conversation

@iliaal

@iliaal iliaal commented Sep 10, 2026

Copy link
Copy Markdown
Member

openssl_pkcs7_verify() and openssl_cms_verify() opened the output paths in write mode before verification, emptying existing files on failure. Verified content is buffered in memory and written only on success; the extra PKCS7/CMS output file is created only in that same success branch.

echo "p7bout sentinel intact? " . (file_get_contents($p7bout) === $sentinel ? "YES" : "NO") . "\n";
echo "signers sentinel intact? " . (file_get_contents($signers) === $sentinel ? "YES" : "NO") . "\n";

foreach ([$plain, $signed, $aCrt, $aKey, $bCrt, $dir . 'pkcs7_verify_nt_b.key.tmp', $content, $p7bout, $signers] as $f) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--CLEAN--?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into --CLEAN--. The inline unlink was skipped whenever the sign step bailed out early.

@iliaal
iliaal force-pushed the fix/openssl-ss004-pre-verify-truncation branch from 15ae602 to 079ba42 Compare September 11, 2026 10:49
…succeeds

openssl_pkcs7_verify() and openssl_cms_verify() opened the content and
p7b output paths in write mode before verify, emptying existing files
when verification failed. Buffer verified content in a memory BIO and
write it only on success; open the p7b path only in that same success
branch. Sibling audit: both verify functions shared the same early-open
pattern; sign/encrypt paths already write after success.
@iliaal
iliaal force-pushed the fix/openssl-ss004-pre-verify-truncation branch from 079ba42 to 43e37d7 Compare September 11, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants