static sig_atomic_t tags_sorted = 0;
static sig_atomic_t entities_sorted = 0;
+static const guint max_tags = 8192; /* Ignore tags if this maximum is reached */
struct html_tag_def {
const gchar *name;
nnode);
}
+ if (hc->total_tags > max_tags) {
+ hc->flags |= RSPAMD_HTML_FLAG_TOO_MANY_TAGS;
+ }
+
if (tag->id == -1) {
/* Ignore unknown tags */
+ hc->total_tags ++;
return FALSE;
}
if (!(tag->flags & CM_INLINE)) {
/* Block tag */
- nnode = g_node_new (tag);
-
if (tag->flags & (FL_CLOSING|FL_CLOSED)) {
if (!*cur_level) {
msg_debug_html ("bad parent node");
- g_node_destroy (nnode);
return FALSE;
}
- g_node_append (*cur_level, nnode);
+ if (hc->total_tags < max_tags) {
+ nnode = g_node_new (tag);
+ g_node_append (*cur_level, nnode);
- if (!rspamd_html_check_balance (nnode, cur_level)) {
- msg_debug_html (
- "mark part as unbalanced as it has not pairable closing tags");
- hc->flags |= RSPAMD_HTML_FLAG_UNBALANCED;
- *balanced = FALSE;
- }
- else {
- *balanced = TRUE;
+ if (!rspamd_html_check_balance (nnode, cur_level)) {
+ msg_debug_html (
+ "mark part as unbalanced as it has not pairable closing tags");
+ hc->flags |= RSPAMD_HTML_FLAG_UNBALANCED;
+ *balanced = FALSE;
+ } else {
+ *balanced = TRUE;
+ }
+
+ hc->total_tags ++;
}
}
else {
hc->flags |= RSPAMD_HTML_FLAG_UNBALANCED;
*balanced = FALSE;
tag->parent = parent->parent;
- g_node_append (parent->parent, nnode);
- *cur_level = nnode;
+
+ if (hc->total_tags < max_tags) {
+ nnode = g_node_new (tag);
+ g_node_append (parent->parent, nnode);
+ *cur_level = nnode;
+ hc->total_tags ++;
+ }
return TRUE;
}
parent->content_length += tag->content_length;
}
- g_node_append (*cur_level, nnode);
+ if (hc->total_tags < max_tags) {
+ nnode = g_node_new (tag);
+ g_node_append (*cur_level, nnode);
+
+ if ((tag->flags & FL_CLOSED) == 0) {
+ *cur_level = nnode;
+ }
- if ((tag->flags & FL_CLOSED) == 0) {
- *cur_level = nnode;
+ hc->total_tags ++;
}
if (tag->flags & (CM_HEAD|CM_UNKNOWN|FL_IGNORE)) {