summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorAlexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>2020-03-10 13:11:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-10 18:41:40 (GMT)
commit3d7747e318532a36a263c61cdf92f2decb6424ff (patch)
tree3d00f009afde0dea8008eb7a40b379c9225023e5 /t
parent0915a5b4cdf00a8c6c755b77b854725a183993b4 (diff)
downloadgit-3d7747e318532a36a263c61cdf92f2decb6424ff.zip
git-3d7747e318532a36a263c61cdf92f2decb6424ff.tar.gz
git-3d7747e318532a36a263c61cdf92f2decb6424ff.tar.bz2
real_path: remove unsafe API
Returning a shared buffer invites very subtle bugs due to reentrancy or multi-threading, as demonstrated by the previous patch. There was an unfinished effort to abolish this [1]. Let's finally rid of `real_path()`, using `strbuf_realpath()` instead. This patch uses a local `strbuf` for most places where `real_path()` was previously called. However, two places return the value of `real_path()` to the caller. For them, a `static` local `strbuf` was added, effectively pushing the problem one level higher: read_gitfile_gently() get_superproject_working_tree() [1] https://lore.kernel.org/git/1480964316-99305-1-git-send-email-bmwill@google.com/ Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rw-r--r--t/helper/test-path-utils.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 409034c..313a153 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -290,11 +290,14 @@ int cmd__path_utils(int argc, const char **argv)
}
if (argc >= 2 && !strcmp(argv[1], "real_path")) {
+ struct strbuf realpath = STRBUF_INIT;
while (argc > 2) {
- puts(real_path(argv[2]));
+ strbuf_realpath(&realpath, argv[2], 1);
+ puts(realpath.buf);
argc--;
argv++;
}
+ strbuf_release(&realpath);
return 0;
}