Skip to content

Commit 4b58006

Browse files
nhormangitster
authored andcommitted
git cherry-pick: do not dereference a potential NULL pointer
In the case the pointer could be NULL, the function that gave the caller the NULL pointer would already have issued an error message, so simply returning early with an error status without issuing a new message is sufficient. The same for parse_commit() that will show necessary error message when the argument is not NULL, and will return error silently when the argument is NULL. Noticed-by: Michael Mueller Signed-off-by: Neil Horman <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90e1818 commit 4b58006

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

sequencer.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,17 @@ static int is_index_unchanged(void)
261261
return error(_("Could not resolve HEAD commit\n"));
262262

263263
head_commit = lookup_commit(head_sha1);
264-
if (!head_commit || parse_commit(head_commit))
265-
return error(_("could not parse commit %s\n"),
266-
sha1_to_hex(head_commit->object.sha1));
264+
265+
/*
266+
* If head_commit is NULL, check_commit, called from
267+
* lookup_commit, would have indicated that head_commit is not
268+
* a commit object already. parse_commit() will return failure
269+
* without further complaints in such a case. Otherwise, if
270+
* the commit is invalid, parse_commit() will complain. So
271+
* there is nothing for us to say here. Just return failure.
272+
*/
273+
if (parse_commit(head_commit))
274+
return -1;
267275

268276
if (!active_cache_tree)
269277
active_cache_tree = cache_tree();

0 commit comments

Comments
 (0)