]> git.ipfire.org Git - thirdparty/git.git/commit - abspath.c
real_path: remove unsafe API
authorAlexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Tue, 10 Mar 2020 13:11:22 +0000 (13:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Mar 2020 18:41:40 +0000 (11:41 -0700)
commit3d7747e318532a36a263c61cdf92f2decb6424ff
tree3d00f009afde0dea8008eb7a40b379c9225023e5
parent0915a5b4cdf00a8c6c755b77b854725a183993b4
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>
13 files changed:
abspath.c
builtin/clone.c
builtin/commit-graph.c
builtin/rev-parse.c
builtin/worktree.c
cache.h
editor.c
environment.c
path.c
setup.c
submodule.c
t/helper/test-path-utils.c
worktree.c