path: root/abspath.c
diff options
authorAlexandr Miloslavskiy <>2020-03-10 13:11:22 (GMT)
committerJunio C Hamano <>2020-03-10 18:41:40 (GMT)
commit3d7747e318532a36a263c61cdf92f2decb6424ff (patch)
tree3d00f009afde0dea8008eb7a40b379c9225023e5 /abspath.c
parent0915a5b4cdf00a8c6c755b77b854725a183993b4 (diff)
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] Signed-off-by: Alexandr Miloslavskiy <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'abspath.c')
1 files changed, 1 insertions, 7 deletions
diff --git a/abspath.c b/abspath.c
index 9857985..d34026b 100644
--- a/abspath.c
+++ b/abspath.c
@@ -206,12 +206,6 @@ error_out:
* Resolve `path` into an absolute, cleaned-up path. The return value
* comes from a shared buffer.
-const char *real_path(const char *path)
- static struct strbuf realpath = STRBUF_INIT;
- return strbuf_realpath(&realpath, path, 1);
const char *real_path_if_valid(const char *path)
static struct strbuf realpath = STRBUF_INIT;
@@ -233,7 +227,7 @@ char *real_pathdup(const char *path, int die_on_error)
* Use this to get an absolute path from a relative one. If you want
- * to resolve links, you should use real_path.
+ * to resolve links, you should use strbuf_realpath.
const char *absolute_path(const char *path)