summaryrefslogtreecommitdiffstats
path: root/t/t7001-mv.sh
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2023-08-09 09:47:41 +0200
committerJunio C Hamano <gitster@pobox.com>2023-08-09 20:46:12 +0200
commit72695d8214791161a943086e894874b4fd71ba9f (patch)
treeca6ce6929e54f372f3a5a26ef1b1ffc3a262430b /t/t7001-mv.sh
parentMerge branch 'jk/redact-h2h3-headers-fix' into maint-2.41 (diff)
downloadgit-72695d8214791161a943086e894874b4fd71ba9f.tar.xz
git-72695d8214791161a943086e894874b4fd71ba9f.zip
mv: handle lstat() failure correctly
When moving a directory onto another with `git mv` various checks are performed. One of of these validates that the destination is not existing. When calling `lstat` on the destination path and it fails as the path doesn't exist, some environments seem to overwrite the passed in `stat` memory nonetheless (I observed this issue on debian 12 of x86_64, running on OrbStack on ARM, emulated with Rosetta). This would affect the code that followed as it would still acccess a now modified `st` structure, which now seems to contain uninitialized memory. `S_ISDIR(st_dir_mode)` would then typically return false causing the code to run into a bad case. The fix avoids overwriting the existing `st` structure, providing an alternative that exists only for that purpose. Note that this patch minimizes complexity instead of stack-frame size. Signed-off-by: Sebastian Thiel <sebastian.thiel@icloud.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7001-mv.sh')
-rwxr-xr-xt/t7001-mv.sh7
1 files changed, 7 insertions, 0 deletions
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 898a920532..f136ea76f7 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -174,6 +174,13 @@ test_expect_success 'do not move directory over existing directory' '
test_must_fail git mv path2 path0
'
+test_expect_success 'rename directory to non-existing directory' '
+ mkdir dir-a &&
+ >dir-a/f &&
+ git add dir-a &&
+ git mv dir-a non-existing-dir
+'
+
test_expect_success 'move into "."' '
git mv path1/path2/ .
'