diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-08-16 14:10:58 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-09-21 12:11:06 +0200 |
commit | 0b9c68b1366e7ef458b4932f066c487498e6c79f (patch) | |
tree | 2527ffff4da5fec42679367dab02d50461d0aca4 | |
parent | df33b43d08f63b0c2b404c5a4b9c17a420232436 (diff) | |
download | libgit2-0b9c68b1366e7ef458b4932f066c487498e6c79f.tar.gz |
submodule: fix submodule names depending on config-owned memory
When populating the list of submodule names, we use the submodule
configuration entry's name as the key in the map of submodule names.
This creates a hidden dependency on the liveliness of the configuration
that was used to parse the submodule, which is fragile and unexpected.
Fix the issue by duplicating the string before writing it into the
submodule name map.
-rw-r--r-- | src/submodule.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/submodule.c b/src/submodule.c index 3cbddfa3e..c7fd50c77 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -199,13 +199,15 @@ out: */ static void free_submodule_names(git_strmap *names) { - git_buf *name; + const char *key; + char *value; if (names == NULL) return; - git_strmap_foreach_value(names, name, { - git__free(name); + git_strmap_foreach(names, key, value, { + git__free((char *) key); + git__free(value); }); git_strmap_free(names); @@ -257,7 +259,7 @@ static int load_submodule_names(git_strmap **out, git_repository *repo, git_conf if (!isvalid) continue; - git_strmap_insert(names, entry->value, git_buf_detach(&buf), &rval); + git_strmap_insert(names, git__strdup(entry->value), git_buf_detach(&buf), &rval); if (rval < 0) { giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table"); error = -1; |