diff options
author | Colin Xu <colin.xu@gmail.com> | 2016-01-22 11:03:37 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-02-17 16:10:33 +0300 |
commit | a218b2f625874d9d9523f05a86845506c4735e66 (patch) | |
tree | 62fbedcedea0cbe5e782dd1cc4d01d00c832d15d /src/iterator.c | |
parent | 4be2aa57c9b512d45b4071b71d0b93f3bf7e18d6 (diff) |
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 <colin.xu@gmail.com>
Diffstat (limited to 'src/iterator.c')
-rw-r--r-- | src/iterator.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/iterator.c b/src/iterator.c index ee348de6e..2d9ebf41d 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -558,7 +558,7 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final) { tree_iterator_frame *tf = ti->head; - if (!tf->up) + if (!tf || !tf->up) return false; ti->head = tf->up; @@ -581,7 +581,8 @@ static void tree_iterator__pop_all(tree_iterator *ti, bool to_end, bool final) while (tree_iterator__pop_frame(ti, final)) /* pop to root */; if (!final) { - ti->head->current = to_end ? ti->head->n_entries : 0; + if(ti->head) + ti->head->current = to_end ? ti->head->n_entries : 0; ti->path_ambiguities = 0; git_buf_clear(&ti->path); } @@ -775,7 +776,8 @@ static void tree_iterator__free(git_iterator *self) tree_iterator__pop_all(ti, true, false); - git_tree_free(ti->head->entries[0]->tree); + if(ti->head) + git_tree_free(ti->head->entries[0]->tree); git__free(ti->head); git_pool_clear(&ti->pool); git_buf_free(&ti->path); |