summaryrefslogtreecommitdiff
path: root/src/diff.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-05-15 14:50:05 -0700
committerRussell Belfer <rb@github.com>2013-05-15 14:50:05 -0700
commit79ef3be449c9d81dd0b37a30999563aa92e4679e (patch)
tree5e4e5d47c1fe3823d4fd2b1c794effcc3263b608 /src/diff.c
parentf0ab73720a4e7a9b37c901a27519ea65eafeb8a6 (diff)
downloadlibgit2-79ef3be449c9d81dd0b37a30999563aa92e4679e.tar.gz
Fix diff crash when last item is untracked dir
When the last item in a diff was an untracked directory that only contained ignored items, the loop to scan the contents would run off the end of the iterator and dereference a NULL pointer. This includes a test that reproduces the problem and a fix.
Diffstat (limited to 'src/diff.c')
-rw-r--r--src/diff.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/diff.c b/src/diff.c
index f466546bb..d93506984 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -747,7 +747,8 @@ static int diff_scan_inside_untracked_dir(
}
/* look for actual untracked file */
- while (!diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) {
+ while (info->nitem != NULL &&
+ !diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) {
is_ignored = git_iterator_current_is_ignored(info->new_iter);
/* need to recurse into non-ignored directories */
@@ -769,7 +770,8 @@ static int diff_scan_inside_untracked_dir(
}
/* finish off scan */
- while (!diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) {
+ while (info->nitem != NULL &&
+ !diff->pfxcomp(info->nitem->path, git_buf_cstr(&base))) {
if ((error = git_iterator_advance(&info->nitem, info->new_iter)) < 0)
break;
}