From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: "Martin Ågren" <martin.agren@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH] bisect: avoid NULL pointer dereference
Date: Mon, 8 Jan 2018 21:36:55 +0100 [thread overview]
Message-ID: <07a8cdae-8f8c-8560-c450-c6089a942c96@web.de> (raw)
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;
--
2.15.1
next reply other threads:[~2018-01-08 20:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 20:36 René Scharfe [this message]
2018-01-08 20:45 ` [PATCH] bisect: avoid NULL pointer dereference Johannes Schindelin
2018-01-08 21:50 ` René Scharfe
2018-01-08 22:15 ` Junio C Hamano
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=07a8cdae-8f8c-8560-c450-c6089a942c96@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=martin.agren@gmail.com \
/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).