Skip to content

Commit 9e723db

Browse files
committed
submodule: plug leaks from the escape detection
1 parent c16ebaa commit 9e723db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/submodule.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,13 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
231231
fdot = strchr(entry->name, '.');
232232
ldot = strrchr(entry->name, '.');
233233

234+
git_buf_clear(&buf);
234235
git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
235236
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
236-
if (isvalid < 0)
237-
return isvalid;
237+
if (isvalid < 0) {
238+
error = isvalid;
239+
goto out;
240+
}
238241
if (!isvalid)
239242
continue;
240243

@@ -244,9 +247,13 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
244247
return -1;
245248
}
246249
}
250+
if (error == GIT_ITEROVER)
251+
error = 0;
247252

253+
out:
254+
git_buf_free(&buf);
248255
git_config_iterator_free(iter);
249-
return 0;
256+
return error;
250257
}
251258

252259
int git_submodule_lookup(

tests/submodule/escape.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void test_submodule_escape__from_gitdir(void)
4343
"[submodule \"" EVIL_SM_NAME "\"]\n"
4444
" path = testrepo\n"
4545
" url = ../testrepo.git\n");
46+
git_buf_free(&buf);
4647

4748
/* Find it all the different ways we know about it */
4849
foundit = 0;
@@ -76,6 +77,7 @@ void test_submodule_escape__from_gitdir_windows(void)
7677
"[submodule \"" EVIL_SM_NAME_WINDOWS "\"]\n"
7778
" path = testrepo\n"
7879
" url = ../testrepo.git\n");
80+
git_buf_free(&buf);
7981

8082
/* Find it all the different ways we know about it */
8183
foundit = 0;

0 commit comments

Comments
 (0)