Skip to content

Commit add8db0

Browse files
committed
Fix use-after-free in submodule reload
If the first call to release a no-longer-existent submodule freed the object, the check if a second is needed would dereference the data that was just freed.
1 parent 041fad4 commit add8db0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/submodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,13 @@ int git_submodule_reload_all(git_repository *repo, int force)
852852
git_strmap_foreach_value(repo->submodules, sm, {
853853
git_strmap *cache = repo->submodules;
854854

855-
if ((sm->flags & GIT_SUBMODULE_STATUS__IN_FLAGS) == 0) {
856-
submodule_cache_remove_item(cache, sm->name, sm, true);
855+
if (sm && (sm->flags & GIT_SUBMODULE_STATUS__IN_FLAGS) == 0) {
856+
/* we must check path != name before first remove, in case
857+
* that call frees the submodule */
858+
bool free_as_path = (sm->path != sm->name);
857859

858-
if (sm->path != sm->name)
860+
submodule_cache_remove_item(cache, sm->name, sm, true);
861+
if (free_as_path)
859862
submodule_cache_remove_item(cache, sm->path, sm, true);
860863
}
861864
});

0 commit comments

Comments
 (0)