commit ff2080b: [Minor] Fix dom save point logic

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jul 7 20:49:05 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-07 21:46:13 +0100
URL: https://github.com/rspamd/rspamd/commit/ff2080b07b5696df0ebd778d49f854f66b828d24 (HEAD -> master)

[Minor] Fix dom save point logic

---
 src/libserver/html/html.cxx | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index a6fcfe36b..b3080bd88 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -1285,7 +1285,7 @@ html_process_input(rspamd_mempool_t *pool,
 		ntag->tag_start = c - start;
 		ntag->flags = flags;
 
-		if (cur_tag && !(cur_tag->flags & (CM_EMPTY|FL_CLOSED))) {
+		if (cur_tag && !(cur_tag->flags & (CM_EMPTY|FL_CLOSED)) && cur_tag != &cur_closing_tag) {
 			parent_tag = cur_tag;
 		}
 
@@ -1308,13 +1308,16 @@ html_process_input(rspamd_mempool_t *pool,
 		}
 
 		/* Shift to the first unclosed tag */
-		while (parent_tag && (parent_tag->flags & FL_CLOSED)) {
-			parent_tag = parent_tag->parent;
+		auto *pt = parent_tag;
+		while (pt && (pt->flags & FL_CLOSED)) {
+			pt = pt->parent;
 		}
 
-		if (parent_tag) {
-			cur_tag->parent = parent_tag;
+		if (pt) {
+			cur_tag->parent = pt;
 			g_assert(cur_tag->parent != cur_tag);
+			g_assert(cur_tag->parent != &cur_closing_tag);
+			parent_tag = pt;
 			parent_tag->children.push_back(cur_tag);
 		}
 		else {
@@ -1810,10 +1813,12 @@ html_process_input(rspamd_mempool_t *pool,
 					vtag->content_offset = p - start + 1;
 					vtag->closing = cur_tag->closing;
 					vtag->parent = cur_opening_tag;
+					g_assert(vtag->parent != &cur_closing_tag);
 					cur_opening_tag->children.push_back(vtag.get());
 					hc->all_tags.emplace_back(std::move(vtag));
 					cur_tag = cur_opening_tag;
 					parent_tag = cur_tag->parent;
+					g_assert(cur_tag->parent != &cur_closing_tag);
 				}
 			} /* if cur_tag != nullptr */
 			state = html_text_content;


More information about the Commits mailing list