From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: Jens Lehmann <Jens.Lehmann@web.de>,
John Keeping <john@keeping.me.uk>,
Junio C Hamano <gitster@pobox.com>,
Guillaume Gelin <contact@ramnes.eu>
Subject: [PATCH v2] mv: prevent mismatched data when ignoring errors.
Date: Sat, 15 Mar 2014 18:56:52 +0000 [thread overview]
Message-ID: <1394909812-92472-1-git-send-email-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <1394306499-50871-1-git-send-email-sandals@crustytoothpaste.net>
We shrink the source and destination arrays, but not the modes or
submodule_gitfile arrays, resulting in potentially mismatched data. Shrink
all the arrays at the same time to prevent this. Add tests to ensure the
problem does not recur.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
I attempted to come up with a second patch that would refactor out the
four different arrays into one array of struct, as Jeff suggested, but
it became very ugly very quickly. So this patch simply fixes the
problem and adds tests.
builtin/mv.c | 5 +++++
t/t7001-mv.sh | 13 ++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index f99c91e..09bbc63 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -230,6 +230,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
memmove(destination + i,
destination + i + 1,
(argc - i) * sizeof(char *));
+ memmove(modes + i, modes + i + 1,
+ (argc - i) * sizeof(enum update_mode));
+ memmove(submodule_gitfile + i,
+ submodule_gitfile + i + 1,
+ (argc - i) * sizeof(char *));
i--;
}
} else
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index e3c8c2c..215d43d 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -294,7 +294,8 @@ test_expect_success 'setup submodule' '
git submodule add ./. sub &&
echo content >file &&
git add file &&
- git commit -m "added sub and file"
+ git commit -m "added sub and file" &&
+ git branch submodule
'
test_expect_success 'git mv cannot move a submodule in a file' '
@@ -463,4 +464,14 @@ test_expect_success 'checking out a commit before submodule moved needs manual u
! test -s actual
'
+test_expect_success 'mv -k does not accidentally destroy submodules' '
+ git checkout submodule &&
+ mkdir dummy dest &&
+ git mv -k dummy sub dest &&
+ git status --porcelain >actual &&
+ grep "^R sub -> dest/sub" actual &&
+ git reset --hard &&
+ git checkout .
+'
+
test_done
--
1.9.0.1010.g6633b85.dirty
next prev parent reply other threads:[~2014-03-15 18:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-08 16:23 git 1.9.0 segfault Guillaume Gelin
2014-03-08 16:46 ` brian m. carlson
2014-03-08 18:12 ` John Keeping
2014-03-08 18:35 ` [PATCH] builtin/mv: fix out of bounds write John Keeping
2014-03-08 19:15 ` brian m. carlson
2014-03-08 19:29 ` [PATCH v2] " John Keeping
2014-03-08 19:21 ` [PATCH] mv: prevent mismatched data when ignoring errors brian m. carlson
2014-03-11 1:56 ` Jeff King
2014-03-11 2:00 ` brian m. carlson
2014-03-11 21:45 ` Junio C Hamano
2014-03-12 23:21 ` brian m. carlson
2014-03-15 16:05 ` Thomas Rast
2014-03-16 2:00 ` Jeff King
2014-03-16 21:20 ` Junio C Hamano
2014-03-17 6:33 ` Junio C Hamano
2014-03-17 15:07 ` Michael Haggerty
2014-03-17 19:06 ` Eric Sunshine
2014-03-17 22:04 ` Jeff King
2014-03-18 22:31 ` Junio C Hamano
2014-03-15 18:56 ` brian m. carlson [this message]
2014-03-16 2:00 ` [PATCH v2] " Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394909812-92472-1-git-send-email-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=Jens.Lehmann@web.de \
--cc=contact@ramnes.eu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=john@keeping.me.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).