git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] bisect: avoid NULL pointer dereference

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 8, 2018, 20:45 UTC
Message-ID
<nycvar.QRO.7.76.6.1801082145140.31@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz>
In-Reply-To
<07a8cdae-8f8c-8560-c450-c6089a942c96@web.de>
Hi René,
On Mon, 8 Jan 2018, René Scharfe wrote:
Show 30 quoted lines
> 7c117184d7 (bisect: fix off-by-one error in `best_bisection_sorted()`)
> fixed an off-by-one error, plugged a memory leak and removed a NULL
> check.  However, the pointer p *is* actually NULL if an empty list is
> passed to the function.  Let's add the check back for safety.  Bisecting
> nothing doesn't make too much sense, but that's no excuse for crashing.
> 
> Found with GCC's -Wnull-dereference.
> 
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  bisect.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/bisect.c b/bisect.c
> index 0fca17c02b..2f3008b078 100644
> --- a/bisect.c
> +++ b/bisect.c
> @@ -229,8 +229,10 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
>  		if (i < cnt - 1)
>  			p = p->next;
>  	}
> -	free_commit_list(p->next);
> -	p->next = NULL;
> +	if (p) {
> +		free_commit_list(p->next);
> +		p->next = NULL;
> +	}
>  	strbuf_release(&buf);
>  	free(array);
>  	return list;

Isn't this identical to https://public-inbox.org/git/20180103184852.27271-1-avarab@gmail.com/ ?

Ciao, Dscho

Previous: René ScharfeNext: René Scharfe
Message 2 of 4 in “bisect: avoid NULL pointer dereference”
  1. bisect: avoid NULL pointer dereferenceRené Scharfe, Jan 8, 2018
  2. Johannes SchindelinJan 8, 2018
  3. René ScharfeJan 8, 2018
  4. Junio C HamanoJan 8, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.