Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a218b2f

Browse files
ivellioscolinEdward Thomson
authored and
Edward Thomson
committed
Validate pointer before access the member.
When Git repository at network locations, sometimes git_iterator_for_tree fails at iterator__update_ignore_case so it goes to git_iterator_free. Null pointer will crash the process if not check. Signed-off-by: Colin Xu <[email protected]>
1 parent 4be2aa5 commit a218b2f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/iterator.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final)
558558
{
559559
tree_iterator_frame *tf = ti->head;
560560

561-
if (!tf->up)
561+
if (!tf || !tf->up)
562562
return false;
563563

564564
ti->head = tf->up;
@@ -581,7 +581,8 @@ static void tree_iterator__pop_all(tree_iterator *ti, bool to_end, bool final)
581581
while (tree_iterator__pop_frame(ti, final)) /* pop to root */;
582582

583583
if (!final) {
584-
ti->head->current = to_end ? ti->head->n_entries : 0;
584+
if(ti->head)
585+
ti->head->current = to_end ? ti->head->n_entries : 0;
585586
ti->path_ambiguities = 0;
586587
git_buf_clear(&ti->path);
587588
}
@@ -775,7 +776,8 @@ static void tree_iterator__free(git_iterator *self)
775776

776777
tree_iterator__pop_all(ti, true, false);
777778

778-
git_tree_free(ti->head->entries[0]->tree);
779+
if(ti->head)
780+
git_tree_free(ti->head->entries[0]->tree);
779781
git__free(ti->head);
780782
git_pool_clear(&ti->pool);
781783
git_buf_free(&ti->path);

0 commit comments

Comments
 (0)