From: Jeff King <peff@peff.net>
To: Jeff Hostetler <git@jeffhostetler.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Jeff Hostetler <jeffhost@microsoft.com>,
Jon Simons <jon@jonsimons.org>,
git@vger.kernel.org, me@ttaylorr.com, sunshine@sunshineco.com,
stolee@gmail.com
Subject: [PATCH 4/3] list-objects-filter: use empty string instead of NULL for sparse "base"
Date: Sun, 15 Sep 2019 12:51:56 -0400 [thread overview]
Message-ID: <20190915165156.GA28436@sigill.intra.peff.net> (raw)
In-Reply-To: <20190915010942.GA19787@sigill.intra.peff.net>
On Sat, Sep 14, 2019 at 09:09:42PM -0400, Jeff King wrote:
> On Mon, Sep 09, 2019 at 01:08:24PM -0400, Jeff King wrote:
>
> > I'll work up what I sent earlier into a real patch, and include some of
> > this discussion.
>
> Here it is. I pulled Jon's tests out into their own patch (mostly
> because it makes it easier to give credit). Then patch 2 is my fix, and
> patch 3 is the message fixups he had done.
>
> This replaces what's queued in js/partial-clone-sparse-blob.
>
> [1/3]: t5616: test cloning/fetching with sparse:oid=<oid> filter
> [2/3]: list-objects-filter: delay parsing of sparse oid
> [3/3]: list-objects-filter: give a more specific error sparse parsing error
And here's a bonus patch that I found while running under ASan/UBSan
(since I wanted to double-check the memory handling of patch 2 when
merged with 'next').
-- >8 --
Subject: list-objects-filter: use empty string instead of NULL for sparse "base"
We use add_excludes_from_blob_to_list() to parse a sparse blob. Since
we don't have a base path, we pass NULL and 0 for the base and baselen,
respectively. But the rest of the exclude code passes a literal empty
string instead of NULL for this case. And indeed, we eventually end up
with match_pathname() calling fspathncmp(), which then calls the system
strncmp(path, base, baselen).
This works on many platforms, which notice that baselen is 0 and do not
look at the bytes of "base" at all. But it does violate the C standard,
and building with SANITIZE=undefined will complain. You can also see it
by instrumenting fspathncmp like this:
diff --git a/dir.c b/dir.c
index d021c908e5..4bb3d3ec96 100644
--- a/dir.c
+++ b/dir.c
@@ -71,6 +71,8 @@ int fspathcmp(const char *a, const char *b)
int fspathncmp(const char *a, const char *b, size_t count)
{
+ if (!a || !b)
+ BUG("null fspathncmp arguments");
return ignore_case ? strncasecmp(a, b, count) : strncmp(a, b, count);
}
We could perhaps be more defensive in match_pathname(), but even if we
did so, it makes sense for this code to match the rest of the exclude
callers.
Signed-off-by: Jeff King <peff@peff.net>
---
list-objects-filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 50f0c6d07b..83c788e8b5 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -472,7 +472,7 @@ static void *filter_sparse_oid__init(
die(_("unable to access sparse blob in '%s'"),
filter_options->sparse_oid_name);
d->omits = omitted;
- if (add_excludes_from_blob_to_list(&sparse_oid, NULL, 0, &d->el) < 0)
+ if (add_excludes_from_blob_to_list(&sparse_oid, "", 0, &d->el) < 0)
die(_("unable to parse sparse filter data in %s"),
oid_to_hex(&sparse_oid));
--
2.23.0.667.gcccf1fbb03
next prev parent reply other threads:[~2019-09-15 16:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 23:19 [PATCH v3 0/2] partial-clone: fix two issues with sparse filter handling Jon Simons
2019-08-29 23:19 ` [PATCH v3 1/2] list-objects-filter: only parse sparse OID when 'have_git_dir' Jon Simons
2019-08-30 18:08 ` Junio C Hamano
2019-09-04 4:54 ` Jeff King
2019-09-05 18:57 ` Junio C Hamano
2019-09-09 13:54 ` Jeff Hostetler
2019-09-09 17:08 ` Jeff King
2019-09-09 20:03 ` Jeff Hostetler
2019-09-15 1:09 ` [PATCH 0/3] clone --filter=sparse:oid bugs Jeff King
2019-09-15 1:11 ` [PATCH 1/3] t5616: test cloning/fetching with sparse:oid=<oid> filter Jeff King
2019-09-15 1:13 ` [PATCH 2/3] list-objects-filter: delay parsing of sparse oid Jeff King
2019-09-15 16:12 ` Jeff King
2019-09-17 19:22 ` Junio C Hamano
2019-09-15 1:13 ` [PATCH 3/3] list-objects-filter: give a more specific error sparse parsing error Jeff King
2019-09-15 16:51 ` Jeff King [this message]
2019-09-16 14:31 ` [PATCH 0/3] clone --filter=sparse:oid bugs Jeff Hostetler
2019-09-09 17:12 ` [PATCH v3 1/2] list-objects-filter: only parse sparse OID when 'have_git_dir' Junio C Hamano
2019-09-09 19:49 ` Jeff Hostetler
2019-08-29 23:19 ` [PATCH v3 2/2] list-objects-filter: handle unresolved sparse filter OID Jon Simons
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190915165156.GA28436@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeffhost@microsoft.com \
--cc=jon@jonsimons.org \
--cc=me@ttaylorr.com \
--cc=stolee@gmail.com \
--cc=sunshine@sunshineco.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).