Re: [PATCH v2] revision.c: fix possible null pointer access
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 7, 2015, 20:31 UTC
- Message-ID
- <xmqqegeym25s.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <1449329244-4585-1-git-send-email-stefan.naewe@gmail.com>
Stefan Naewe <stefan.naewe@gmail.com> writes:
Show 5 quoted lines
> mark_tree_uninteresting dereferences a tree pointer before checking > if the pointer is valid. Fix that by doing the check first. > > Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com> > ---
I still have a problem with "dereferences", as "dereference" is about computing an address and accessing memory based on the result, and only the first half is happening here. I can live with "The function does a pointer arithmetic on 'tree' before it makes sure that 'tree' is not NULL", but in any case, let's queue this as-is for now and wait for a while to see if others can come up with a more appropriate phrases.
Thanks.
Show 21 quoted lines
> revision.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/revision.c b/revision.c
> index 0fbb684..8c569cc 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -135,10 +135,12 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
>
> void mark_tree_uninteresting(struct tree *tree)
> {
> - struct object *obj = &tree->object;
> + struct object *obj;
>
> if (!tree)
> return;
> +
> + obj = &tree->object;
> if (obj->flags & UNINTERESTING)
> return;
> obj->flags |= UNINTERESTING;