From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH 1/5] list_objects_filter_copy(): deep-copy sparse_oid_name field
Date: Thu, 8 Sep 2022 00:54:29 -0400 [thread overview]
Message-ID: <Yxl1hcX97W4wpWNj@coredump.intra.peff.net> (raw)
In-Reply-To: <Yxl1BNQoy6Drf0Oe@coredump.intra.peff.net>
The purpose of our copy function is to do a deep copy of each field so
that the source and destination structs become independent. We correctly
copy the filter_spec string list, but we forgot the sparse_oid_name
field. By doing a shallow copy of the pointer, that puts us at risk for
a use-after-free if one or both of the structs is cleaned up.
I don't think this can be triggered in practice, because we tend to leak
the structs rather than actually clean them up. But this should
future-proof us for plugging those leaks.
Signed-off-by: Jeff King <peff@peff.net>
---
I think this is the only thing missing. You can correlate with the
_release() function to see what other things might need a deep copy, and
everything else seems covered.
list-objects-filter-options.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index 4b25287886..41c41c9d45 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -418,6 +418,7 @@ void list_objects_filter_copy(
string_list_init_dup(&dest->filter_spec);
for_each_string_list_item(item, &src->filter_spec)
string_list_append(&dest->filter_spec, item->string);
+ dest->sparse_oid_name = xstrdup_or_null(src->sparse_oid_name);
ALLOC_ARRAY(dest->sub, dest->sub_alloc);
for (i = 0; i < src->sub_nr; i++)
--
2.37.3.1139.g47294c03c7
next prev parent reply other threads:[~2022-09-08 4:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 4:52 [PATCH 0/5] plugging some list-objects-filter leaks Jeff King
2022-09-08 4:54 ` Jeff King [this message]
2022-09-08 4:57 ` [PATCH 2/5] transport: deep-copy object-filter struct for fetch-pack Jeff King
2022-09-08 4:58 ` [PATCH 3/5] transport: free filter options in disconnect_git() Jeff King
2022-09-08 5:01 ` [PATCH 4/5] list_objects_filter_options: plug leak of filter_spec strings Jeff King
2022-09-08 5:02 ` [PATCH 5/5] prepare_repo_settings(): plug leak of config values Jeff King
2022-09-09 14:20 ` [PATCH 0/5] plugging some list-objects-filter leaks Derrick Stolee
2022-09-11 4:51 ` Jeff King
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=Yxl1hcX97W4wpWNj@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
/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).