Skip to content

Commit fdc2c3a

Browse files
committed
apply: do not read from beyond a symbolic link
We should reject a patch, whether it renames/copies dir/file to elsewhere with or without modificiation, or updates dir/file in place, if "dir/" part is actually a symbolic link to elsewhere, by making sure that the code to read the preimage does not read from a path that is beyond a symbolic link. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c37a2e commit fdc2c3a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

builtin/apply.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,8 @@ static int load_patch_target(struct strbuf *buf,
31453145
return read_file_or_gitlink(ce, buf);
31463146
else
31473147
return SUBMODULE_PATCH_WITHOUT_INDEX;
3148+
} else if (has_symlink_leading_path(name, strlen(name))) {
3149+
return error(_("reading from '%s' beyond a symbolic link"), name);
31483150
} else {
31493151
if (read_old_data(st, name, buf))
31503152
return error(_("read of %s failed"), name);

t/t4122-apply-symlink-inside.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,23 @@ test_expect_success 'check result' '
5252
5353
'
5454

55+
test_expect_success SYMLINKS 'do not read from beyond symbolic link' '
56+
git reset --hard &&
57+
mkdir -p arch/x86_64/dir &&
58+
>arch/x86_64/dir/file &&
59+
git add arch/x86_64/dir/file &&
60+
echo line >arch/x86_64/dir/file &&
61+
git diff >patch &&
62+
git reset --hard &&
63+
64+
mkdir arch/i386/dir &&
65+
>arch/i386/dir/file &&
66+
ln -s ../i386/dir arch/x86_64/dir &&
67+
68+
test_must_fail git apply patch &&
69+
test_must_fail git apply --cached patch &&
70+
test_must_fail git apply --index patch
71+
72+
'
73+
5574
test_done

0 commit comments

Comments
 (0)