From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 01/20] mailinfo: fix leaking header data
Date: Tue, 20 Aug 2024 12:25:38 -0700 [thread overview]
Message-ID: <xmqq5xrv8099.fsf@gitster.g> (raw)
In-Reply-To: <69e30ea5179eff6472be54ebba64ebca3e562f32.1724159575.git.ps@pks.im> (Patrick Steinhardt's message of "Tue, 20 Aug 2024 16:05:02 +0200")
Patrick Steinhardt <ps@pks.im> writes:
> We populate the `mailinfo` arrays `p_hdr_data` and `s_hdr_data` with
> data parsed from the mail headers. These arrays may end up being only
> partially populated with gaps in case some of the headers do not parse
> properly. This causes memory leaks because `strbuf_list_free()` will
> stop iterating once it hits the first `NULL` pointer in the backing
> array.
>
> Fix this by open-coding a variant of `strbuf_list_free()` that knows to
> iterate through all headers.
Well spotted. An array of strbuf is often a wrong data structure
for anything, but luckily we use it and suffer from a bug like this
only rarely.
The fix makes sense. Will queue.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> mailinfo.c | 17 +++++++++++++++--
> t/t5100-mailinfo.sh | 1 +
> 2 files changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/mailinfo.c b/mailinfo.c
> index 94b9b0abf22..a4fa64994ac 100644
> --- a/mailinfo.c
> +++ b/mailinfo.c
> @@ -1290,8 +1290,21 @@ void clear_mailinfo(struct mailinfo *mi)
> strbuf_release(&mi->inbody_header_accum);
> free(mi->message_id);
>
> - strbuf_list_free(mi->p_hdr_data);
> - strbuf_list_free(mi->s_hdr_data);
> + for (size_t i = 0; header[i]; i++) {
> + if (!mi->p_hdr_data[i])
> + continue;
> + strbuf_release(mi->p_hdr_data[i]);
> + free(mi->p_hdr_data[i]);
> + }
> + free(mi->p_hdr_data);
> +
> + for (size_t i = 0; header[i]; i++) {
> + if (!mi->s_hdr_data[i])
> + continue;
> + strbuf_release(mi->s_hdr_data[i]);
> + free(mi->s_hdr_data[i]);
> + }
> + free(mi->s_hdr_data);
>
> while (mi->content < mi->content_top) {
> free(*(mi->content_top));
> diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh
> index c8d06554541..065156c1f39 100755
> --- a/t/t5100-mailinfo.sh
> +++ b/t/t5100-mailinfo.sh
> @@ -5,6 +5,7 @@
>
> test_description='git mailinfo and git mailsplit test'
>
> +TEST_PASSES_SANITIZE_LEAK=true
> . ./test-lib.sh
>
> DATA="$TEST_DIRECTORY/t5100"
next prev parent reply other threads:[~2024-08-20 19:25 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 14:04 [PATCH 00/20] Memory leak fixes (pt.5) Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 01/20] mailinfo: fix leaking header data Patrick Steinhardt
2024-08-20 19:25 ` Junio C Hamano [this message]
2024-08-20 14:05 ` [PATCH 02/20] convert: fix leaks when resetting attributes Patrick Steinhardt
2024-08-20 19:51 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 03/20] pretty: fix memory leaks when parsing pretty formats Patrick Steinhardt
2024-08-20 20:36 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 04/20] pretty: fix leaking key/value separator buffer Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 05/20] builtin/merge-tree: fix leaking `-X` strategy options Patrick Steinhardt
2024-08-20 22:10 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 08/20] midx-write: fix leaking hashfile on error cases Patrick Steinhardt
2024-08-20 23:19 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 09/20] builtin/repack: fix leaks when computing packs to repack Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 11/20] transport: fix leaking OID arrays in git:// transport data Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 12/20] builtin/send-pack: fix leaking refspecs Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 13/20] sideband: fix leaks when configuring sideband colors Patrick Steinhardt
2024-08-20 23:52 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 14/20] builtin/fetch-pack: fix leaking refs Patrick Steinhardt
2024-08-21 17:46 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 15/20] remote: fix leaking config strings Patrick Steinhardt
2024-08-21 17:58 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-22 16:04 ` Junio C Hamano
2024-08-20 14:05 ` [PATCH 16/20] remote: fix leaks when matching refspecs Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 17/20] remote: fix leaking peer ref when expanding refmap Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 18/20] builtin/fetch: fix leaking transaction with `--atomic` Patrick Steinhardt
2024-08-20 14:05 ` [PATCH 19/20] transport: fix leaking arguments when fetching from bundle Patrick Steinhardt
2024-08-21 18:07 ` Junio C Hamano
2024-08-22 8:19 ` Patrick Steinhardt
2024-08-22 16:06 ` Junio C Hamano
2024-08-20 14:06 ` [PATCH 20/20] transport: fix leaking negotiation tips Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 00/20] Memory leak fixes (pt.5) Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 01/20] mailinfo: fix leaking header data Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 02/20] convert: fix leaks when resetting attributes Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 03/20] pretty: fix memory leaks when parsing pretty formats Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 04/20] pretty: fix leaking key/value separator buffer Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 05/20] builtin/merge-tree: fix leaking `-X` strategy options Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 06/20] builtin/upload-archive: fix leaking args passed to `write_archive()` Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 07/20] builtin/archive: fix leaking `OPT_FILENAME()` value Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 08/20] midx-write: fix leaking hashfile on error cases Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 09/20] builtin/repack: fix leaks when computing packs to repack Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 10/20] t/helper: fix leaking multi-pack-indices in "read-midx" Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 11/20] transport: fix leaking OID arrays in git:// transport data Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 12/20] builtin/send-pack: fix leaking refspecs Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 13/20] sideband: fix leaks when configuring sideband colors Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 14/20] builtin/fetch-pack: fix leaking refs Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 15/20] remote: fix leaking config strings Patrick Steinhardt
2024-08-22 9:17 ` [PATCH v2 16/20] remote: fix leaks when matching refspecs Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 17/20] remote: fix leaking peer ref when expanding refmap Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 18/20] builtin/fetch: fix leaking transaction with `--atomic` Patrick Steinhardt
2024-08-22 9:18 ` [PATCH v2 19/20] transport: fix leaking arguments when fetching from bundle Patrick Steinhardt
2024-08-22 18:21 ` Junio C Hamano
2024-08-22 9:18 ` [PATCH v2 20/20] transport: fix leaking negotiation tips Patrick Steinhardt
2024-08-22 19:01 ` [PATCH v2 00/20] Memory leak fixes (pt.5) Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq5xrv8099.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).