diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-07-27 20:19:58 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-07-27 20:19:58 +0100 |
commit | d5501813bc81c75275ab2d25f54a9d65cd0eaf60 (patch) | |
tree | d44b3f0296e1e0426d902e68e87a23ac28536d66 /src/libserver | |
parent | 9da164227d682ec31325b69a3fdd0278f00f9c8b (diff) | |
download | rspamd-d5501813bc81c75275ab2d25f54a9d65cd0eaf60.tar.gz rspamd-d5501813bc81c75275ab2d25f54a9d65cd0eaf60.zip |
[Minor] Add more safety checks when adding content
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/html/html.cxx | 21 |
1 files 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 */ |