diff --git a/php_mailparse_mime.c b/php_mailparse_mime.c index 13caa99..5e8e5bf 100644 --- a/php_mailparse_mime.c +++ b/php_mailparse_mime.c @@ -267,6 +267,11 @@ static struct php_mimeheader_with_attributes *php_mimeheader_alloc_from_tok(php_ } namechanged = 0; + } else if (name && name != name_buf) { + /* plain parameter repeating the active RFC2231 name + * (a separate allocation from name_buf): free the name + * that would otherwise leak */ + efree(name); } } else { add_assoc_string(&attr->attributes, name, value); diff --git a/tests/rfc2231_duplicate_plain_name.phpt b/tests/rfc2231_duplicate_plain_name.phpt new file mode 100644 index 0000000..cbb54d1 --- /dev/null +++ b/tests/rfc2231_duplicate_plain_name.phpt @@ -0,0 +1,20 @@ +--TEST-- +A plain parameter repeating an RFC2231 encoded name does not leak the name +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(10) "text/plain" +string(1) "a" +done