Skip to content

Commit ac900fd

Browse files
Martin Ågrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98a1364 commit ac900fd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

progress.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,12 @@ static void finish_if_sparse(struct progress *progress)
319319

320320
void stop_progress(struct progress **p_progress)
321321
{
322+
if (!p_progress)
323+
BUG("don't provide NULL to stop_progress");
324+
322325
finish_if_sparse(*p_progress);
323326

324-
if (p_progress && *p_progress) {
327+
if (*p_progress) {
325328
trace2_data_intmax("progress", the_repository, "total_objects",
326329
(*p_progress)->total);
327330

@@ -342,7 +345,12 @@ void stop_progress(struct progress **p_progress)
342345

343346
void stop_progress_msg(struct progress **p_progress, const char *msg)
344347
{
345-
struct progress *progress = *p_progress;
348+
struct progress *progress;
349+
350+
if (!p_progress)
351+
BUG("don't provide NULL to stop_progress_msg");
352+
353+
progress = *p_progress;
346354
if (!progress)
347355
return;
348356
*p_progress = NULL;

0 commit comments

Comments
 (0)