]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: istream-header-filter - Call callbacks in their own data stack frames
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 09:59:33 +0000 (04:59 -0500)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 21:50:37 +0000 (23:50 +0200)
This makes sure the data stack memory usage won't grow too much while
parsing a large number of headers.

src/lib-mail/istream-header-filter.c

index 83a73b028e9d43ffbf29d7964812b1833d573d33..168242dbd5c0aa496b0173af17e30e6bf226bc77 100644 (file)
@@ -235,11 +235,11 @@ static ssize_t read_header(struct header_filter_istream *mstream)
                        if (mstream->header_parsed && !mstream->headers_edited) {
                                if (mstream->eoh_not_matched)
                                        matched = !matched;
-                       } else if (mstream->callback != NULL) {
+                       } else if (mstream->callback != NULL) T_BEGIN {
                                mstream->callback(mstream, hdr, &matched,
                                                  mstream->context);
                                mstream->callbacks_called = TRUE;
-                       }
+                       } T_END;
 
                        if (matched) {
                                mstream->eoh_not_matched = TRUE;
@@ -274,8 +274,10 @@ static ssize_t read_header(struct header_filter_istream *mstream)
                        bool orig_matched = matched;
 
                        mstream->parsed_lines = mstream->cur_line;
-                       mstream->callback(mstream, hdr, &matched,
-                                         mstream->context);
+                       T_BEGIN {
+                               mstream->callback(mstream, hdr, &matched,
+                                                 mstream->context);
+                       } T_END;
                        mstream->callbacks_called = TRUE;
                        if (matched != orig_matched &&
                            !hdr->continued && !mstream->headers_edited) {