]> git.ipfire.org Git - thirdparty/git.git/commit - progress.c
progress: don't dereference before checking for NULL
authorMartin Ågren <martin.agren@gmail.com>
Mon, 10 Aug 2020 19:47:48 +0000 (21:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Aug 2020 21:59:57 +0000 (14:59 -0700)
commitac900fddb7fd3cc760ea5c1b79a50ad4564e4a0d
treede9480180f8ff9baf60942dd020c2e54e62371b3
parent98a136474082cdc7228d7e0e45672c5274fab701
progress: don't dereference before checking for NULL

In `stop_progress()`, we're careful to check that `p_progress` is
non-NULL before we dereference it, but by then we have already
dereferenced it when calling `finish_if_sparse(*p_progress)`. And, for
what it's worth, we'll go on to blindly dereference it again inside
`stop_progress_msg()`.

We could return early if we get a NULL-pointer, but let's go one step
further and BUG instead. The progress API handles NULL just fine, but
that's the NULL-ness of `*p_progress`, e.g., when running with
`--no-progress`. If `p_progress` is NULL, chances are that's a mistake.
For symmetry, let's do the same check in `stop_progress_msg()`, too.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
progress.c