From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Stefan Sperling <stsp@stsp.name>, git@vger.kernel.org
Subject: Re: [PATCH] fix segv with corrupt tag object
Date: Fri, 30 Aug 2019 09:29:03 -0700 [thread overview]
Message-ID: <xmqqh85yzkfk.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <c6601cca-7de0-ba82-2e18-916a2e9048d3@web.de> ("René Scharfe"'s message of "Thu, 29 Aug 2019 21:06:22 +0200")
René Scharfe <l.s.r@web.de> writes:
> Subject: [PATCH] tree: simplify parse_tree_indirect()
>
> Reduce code duplication by turning parse_tree_indirect() into a wrapper
> of repo_peel_to_type(). This avoids a segfault when handling a broken
> tag where ->tagged is NULL. The new version also checks the return
> value of parse_object() that was ignored by the old one.
>
> Initial-patch-by: Stefan Sperling <stsp@stsp.name>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> tree.c | 18 +++---------------
> 1 file changed, 3 insertions(+), 15 deletions(-)
>
> diff --git a/tree.c b/tree.c
> index 4720945e6a..1466bcc6a8 100644
> --- a/tree.c
> +++ b/tree.c
> @@ -244,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
>
> struct tree *parse_tree_indirect(const struct object_id *oid)
> {
> - struct object *obj = parse_object(the_repository, oid);
> - do {
> - if (!obj)
> - return NULL;
> - if (obj->type == OBJ_TREE)
> - return (struct tree *) obj;
> - else if (obj->type == OBJ_COMMIT)
> - obj = &(get_commit_tree(((struct commit *)obj))->object);
> - else if (obj->type == OBJ_TAG)
> - obj = ((struct tag *) obj)->tagged;
> - else
> - return NULL;
> - if (!obj->parsed)
> - parse_object(the_repository, &obj->oid);
> - } while (1);
> + struct repository *r = the_repository;
> + struct object *obj = parse_object(r, oid);
> + return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
> }
Looks quite sensible to me; it is too simple that it makes me
worried that I might be missing something huge.
prev parent reply other threads:[~2019-08-30 16:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-24 23:09 [PATCH] fix segv with corrupt tag object Stefan Sperling
2019-08-25 7:52 ` René Scharfe
2019-08-26 11:57 ` Stefan Sperling
2019-08-26 17:20 ` Junio C Hamano
2019-08-26 18:02 ` Stefan Sperling
2019-08-26 18:18 ` Jeff King
2019-08-29 19:06 ` René Scharfe
2019-08-30 16:29 ` Junio C Hamano [this message]
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=xmqqh85yzkfk.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=stsp@stsp.name \
/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).