commit d550181: [Minor] Add more safety checks when adding content
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Jul 27 19:21:07 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-07-27 20:19:58 +0100
URL: https://github.com/rspamd/rspamd/commit/d5501813bc81c75275ab2d25f54a9d65cd0eaf60 (HEAD -> master)
[Minor] Add more safety checks when adding content
---
src/libserver/html/html.cxx | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index 716d944ea..0d76a22da 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -984,10 +984,16 @@ html_process_block_tag(rspamd_mempool_t *pool, struct html_tag *tag,
}
static inline auto
-html_append_parsed(struct html_content *hc, std::string_view data, bool transparent) -> auto
+html_append_parsed(struct html_content *hc, std::string_view data, bool transparent,
+ std::size_t input_len) -> std::size_t
{
auto cur_offset = hc->parsed.size();
+ if (hc->parsed.size() > input_len) {
+ /* Impossible case, refuse to append */
+ return 0;
+ }
+
if (data.size() > 0) {
/* Handle multiple spaces at the begin */
@@ -1171,8 +1177,9 @@ html_append_tag_content(rspamd_mempool_t *pool,
goffset initial_part_len = enclosed_start - cur_offset;
if (is_visible && initial_part_len > 0) {
- html_append_parsed(hc, {start + cur_offset,
- std::size_t(initial_part_len)}, is_transparent);
+ html_append_parsed(hc,
+ {start + cur_offset, std::size_t(initial_part_len)},
+ is_transparent, len);
}
auto next_offset = html_append_tag_content(pool, start, len,
@@ -1188,8 +1195,10 @@ html_append_tag_content(rspamd_mempool_t *pool,
goffset final_part_len = tag->closing.start - cur_offset;
if (is_visible && final_part_len > 0) {
- html_append_parsed(hc, {start + cur_offset,
- std::size_t(final_part_len)}, is_transparent);
+ html_append_parsed(hc,
+ {start + cur_offset, std::size_t(final_part_len)},
+ is_transparent,
+ len);
}
}
if (is_block) {
@@ -1966,7 +1975,7 @@ html_process_input(rspamd_mempool_t *pool,
}
break;
case tags_limit_overflow:
- html_append_parsed(hc, {c, (std::size_t) (end - c)}, false);
+ html_append_parsed(hc, {c, (std::size_t) (end - c)}, false, end - start);
break;
default:
/* Do nothing */
More information about the Commits
mailing list