Skip to content

Commit 76141ea

Browse files
committed
mbstring: Fix memory leak in mail header parsing
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.
1 parent 17f6752 commit 76141ea

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ext/mbstring/mbstring.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,9 @@ static int _php_mbstr_parse_mail_headers(HashTable *ht, const char *str, size_t
44534453

44544454
zend_string_release_ex(fld_name, 0);
44554455
}
4456+
else if (fld_name != NULL) {
4457+
zend_string_release_ex(fld_name, 0);
4458+
}
44564459

44574460
fld_name = fld_val = NULL;
44584461
token = (char*)ps;
@@ -4498,6 +4501,9 @@ static int _php_mbstr_parse_mail_headers(HashTable *ht, const char *str, size_t
44984501

44994502
zend_string_release_ex(fld_name, 0);
45004503
}
4504+
else if (fld_name != NULL) {
4505+
zend_string_release_ex(fld_name, 0);
4506+
}
45014507
}
45024508
return state;
45034509
}

0 commit comments

Comments
 (0)