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>
This commit is contained in:
committed by
Junio C Hamano
parent
0915a5b4cd
commit
3d7747e318
@ -857,7 +857,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
||||
if (!gitdir && !prefix)
|
||||
gitdir = ".git";
|
||||
if (gitdir) {
|
||||
puts(real_path(gitdir));
|
||||
struct strbuf realpath = STRBUF_INIT;
|
||||
strbuf_realpath(&realpath, gitdir, 1);
|
||||
puts(realpath.buf);
|
||||
strbuf_release(&realpath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user