[php-src] PHP-8.5: ext/standard: Fix memory leak in get_meta_tags() on tag opened while expecting attribute value (GH-25479)
| From: | Jorg Sowa | Date: | Mon, 16 Nov 2026 21:51:16 +0000 |
| Subject: | [php-src] PHP-8.5: ext/standard: Fix memory leak in get_meta_tags() on tag opened while expecting attribute value (GH-25479) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143751@lists.php.net to get a copy of this message | ||
Author: Jorg Sowa (jorgsowa)
Date: 2026-11-16T22:40:26+01:00
Commit: https://github.com/php/php-src/commit/0a11544b158c2e43e6432e7fadf3cea0a81269e9
Raw diff: https://github.com/php/php-src/commit/0a11544b158c2e43e6432e7fadf3cea0a81269e9.diff
ext/standard: Fix memory leak in get_meta_tags() on tag opened while expecting attribute value
(GH-25479)
Closes GH-25479
Changed paths:
A ext/standard/tests/strings/get_meta_tags_open_tag_leak.phpt
M NEWS
M ext/standard/file.c
Diff:
diff --git a/NEWS b/NEWS
index d98e18da8d42..84e8fdd0473b 100644
--- a/NEWS
+++ b/NEWS
@@ -442,6 +442,8 @@ PHP NEWS
(Marti2203)
. Fixed unserialize() of enums sharing its state with the unserialize()
calls made by autoloaders. (nicolas-grekas)
+ . Fixed memory leak in get_meta_tags() when a tag opens while an attribute
+ value is expected. (Jorg Sowa)
- Streams:
. Fixed bug GH-22063 (Stream filter chain UAF on self-removal during
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 412af159f19e..eab4aa7f4b74 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -348,13 +348,10 @@ PHP_FUNCTION(get_meta_tags)
} else {
add_assoc_string(return_value, name, "");
}
-
- efree(name);
- if (value) efree(value);
- } else if (have_content) {
- efree(value);
}
+ if (name) efree(name);
+ if (value) efree(value);
name = value = NULL;
/* Reset all of our flags */
diff --git a/ext/standard/tests/strings/get_meta_tags_open_tag_leak.phpt
b/ext/standard/tests/strings/get_meta_tags_open_tag_leak.phpt
new file mode 100644
index 000000000000..01f8e4253670
--- /dev/null
+++ b/ext/standard/tests/strings/get_meta_tags_open_tag_leak.phpt
@@ -0,0 +1,25 @@
+--TEST--
+get_meta_tags() does not leak when a tag opens while an attribute value is expected
+--FILE--
+<?php
+
+$filename = __DIR__."/get_meta_tags_open_tag_leak.html";
+
+file_put_contents($filename, <<<HTML
+<meta name="foo" content=<meta>
+<meta content="bar" name=<meta>
+<meta name="baz" content="qux">
+HTML);
+
+var_dump(get_meta_tags($filename));
+
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__."/get_meta_tags_open_tag_leak.html");
+?>
+--EXPECT--
+array(1) {
+ ["baz"]=>
+ string(3) "qux"
+}