Skip to content

mbstring: Fix memory leak in mail header parsing#22254

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:leak-fix-mbstring-mail-headers-84
Open

mbstring: Fix memory leak in mail header parsing#22254
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:leak-fix-mbstring-mail-headers-84

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Jun 7, 2026

A mail header consisting of a field name with no value (the input ends right after the colon) leaves the fld_name zend_string allocated but never released, because the cleanup only runs when both fld_name and fld_val are set. Reproduces via mb_send_mail() with a header like "X-Leak:". It is released in both the loop-body and end-of-input branches.

@alexdowad
Copy link
Copy Markdown
Contributor

@iliaal Thanks for discovering this issue!

It looks to me like this could be written more concisely in the form:

if (fld_name != NULL) {
  if (fld_val != NULL) {
    // Previous logic for downcasing fld_name and storing it in hashtable here
  }
  // Release fld_name here
}

Am I missing something?

@alexdowad
Copy link
Copy Markdown
Contributor

@iliaal To avoid unnecessary back-and-forth, please make sure that your code matches the style of the surrounding code.

A header field name with no value (input ending at the colon) leaves
fld_name allocated but unreleased, since the cleanup blocks only fire
when both fld_name and fld_val are set. Release the dangling fld_name in
both the loop-body and end-of-input branches.
@iliaal iliaal force-pushed the leak-fix-mbstring-mail-headers-84 branch from 76141ea to 8f1b7c2 Compare June 8, 2026 11:35
@iliaal
Copy link
Copy Markdown
Contributor Author

iliaal commented Jun 8, 2026

Right, that's cleaner and drops the duplicated release. Reworked both blocks.

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