]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse_tag_buffer(): treat NULL tag pointer as parse error
authorJeff King <peff@peff.net>
Fri, 18 Oct 2019 04:45:35 +0000 (00:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Oct 2019 02:15:23 +0000 (11:15 +0900)
When parsing a tag, we may end up with a NULL "tagged" field when
there's a type mismatch (e.g., the tag claims to point to object X as a
commit, but we previously saw X as a blob in the same process), but we
do not otherwise indicate a parse failure to the caller.

This is similar to the case discussed in the previous commit, where a
commit could end up with a NULL tree field: while slightly convenient
for callers who want to overlook a corrupt object, it means that normal
callers have to explicitly deal with this case (rather than just relying
on the return code from parsing). And most don't, leading to segfault
fixes like the one in c77722b3ea (use get_tagged_oid(), 2019-09-05).

Let's address this more centrally, by returning an error code from the
parse itself, which most callers would already notice (adventurous
callers are free to ignore the error and continue looking at the
struct).

This also covers the case where the tag contains a nonsensical "type"
field (there we produced a user-visible error but still returned success
to the caller; now we'll produce a slightly better message and return an
error).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tag.c

diff --git a/tag.c b/tag.c
index bfa0e3143580f4f817fa0722a77224e81c58b615..6a51efda8d7d59872159e602486ff43ff739c3f4 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -167,10 +167,15 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
        } else if (!strcmp(type, tag_type)) {
                item->tagged = (struct object *)lookup_tag(r, &oid);
        } else {
-               error("Unknown type %s", type);
-               item->tagged = NULL;
+               return error("unknown tag type '%s' in %s",
+                            type, oid_to_hex(&item->object.oid));
        }
 
+       if (!item->tagged)
+               return error("bad tag pointer to %s in %s",
+                            oid_to_hex(&oid),
+                            oid_to_hex(&item->object.oid));
+
        if (bufptr + 4 < tail && starts_with(bufptr, "tag "))
                ;               /* good */
        else