Fix possible segfault when cloning a submodule shallow.
Signed-off-by: Ali Utku Selen <auselen@gmail.com> --- It is possible to have unallocated slabs in shallow.c's commit_depth for a shallow submodule with many commits.
Easiest way to reproduce this I found was changing COMMIT_SLAB_SIZE to 32 and run t7406-submodule-update.sh. Segfault happens in case 50: "submodule update clone shallow submodule outside of depth"
shallow.c | 2 ++ 1 file changed, 2 insertions(+)
Show changes to shallow.c +2 −0
diff --git a/shallow.c b/shallow.c index 5fa2b15d37..c33ab94bd7 100644 --- a/shallow.c +++ b/shallow.c @@ -156,6 +156,8 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth, for (i = 0; i < depths.slab_count; i++) { int j; + if (!depths.slab[i]) + continue; for (j = 0; j < depths.slab_size; j++) free(depths.slab[i][j]); }
-- 2.17.1