From 6b763c424e4ace1678ade5310f3ca3ffbd11af2c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 5 Sep 2007 21:58:40 -0700 Subject: git-apply: do not read past the end of buffer When the preimage we are patching is shorter than what the patch text expects, we tried to match the buffer contents at the "original" line with the fragment in full, without checking we have enough data to match in the preimage. This caused the size of a later memmove() to wrap around and attempt to scribble almost the entire address space. Not good. The code that follows the part this patch touches tries to match the fragment with line offsets. Curiously, that code does not have the problem --- it guards against reading past the end of the preimage. Signed-off-by: Junio C Hamano diff --git a/builtin-apply.c b/builtin-apply.c index 25b1447..976ec77 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1514,7 +1514,8 @@ static int find_offset(const char *buf, unsigned long size, const char *fragment } /* Exact line number? */ - if (!memcmp(buf + start, fragment, fragsize)) + if ((start + fragsize <= size) && + !memcmp(buf + start, fragment, fragsize)) return start; /* diff --git a/t/t4123-apply-shrink.sh b/t/t4123-apply-shrink.sh new file mode 100755 index 0000000..984157f --- /dev/null +++ b/t/t4123-apply-shrink.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +test_description='apply a patch that is larger than the preimage' + +. ./test-lib.sh + +cat >F <<\EOF +1 +2 +3 +4 +5 +6 +7 +8 +999999 +A +B +C +D +E +F +G +H +I +J + +EOF + +test_expect_success setup ' + + git add F && + mv F G && + sed -e "s/1/11/" -e "s/999999/9/" -e "s/H/HH/" F && + git diff >patch && + sed -e "/^\$/d" F && + git add F + +' + +test_expect_success 'apply should fail gracefully' ' + + if git apply --index patch + then + echo Oops, should not have succeeded + false + else + status=$? + echo "Status was $status" + if test -f .git/index.lock + then + echo Oops, should not have crashed + false + fi + fi +' + +test_done -- cgit v0.10.2-6-g49f6 From ea09ea22d65d118328642e03ad23c8257304499d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 5 Sep 2007 23:33:41 -0400 Subject: Don't allow contrib/workdir/git-new-workdir to trash existing dirs Recently I found that doing a sequence like the following: git-new-workdir a b ... git-new-workdir a b by accident will cause a (and now also b) to have an infinite cycle in its refs directory. This is caused by git-new-workdir trying to create the "refs" symlink over again, only during the second time it is being created within a's refs directory and is now also pointing back at a's refs. This causes confusion in git as suddenly branches are named things like "refs/refs/refs/refs/refs/refs/refs/heads/foo" instead of the more commonly accepted "refs/heads/foo". Plenty of commands start to see ambiguous ref names and others just take ages to compute. git-clone has the same safety check, so git-new-workdir should behave just like it. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir index c6e154a..2838546 100755 --- a/contrib/workdir/git-new-workdir +++ b/contrib/workdir/git-new-workdir @@ -48,6 +48,12 @@ then "a complete repository." fi +# don't recreate a workdir over an existing repository +if test -e "$new_workdir" +then + die "destination directory '$new_workdir' already exists." +fi + # make sure the the links use full paths git_dir=$(cd "$git_dir"; pwd) -- cgit v0.10.2-6-g49f6 From 6b1b40d9f41cdc1db9ad60f143c08f8260eef815 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 6 Sep 2007 03:22:51 +0400 Subject: Makefile: Add cache-tree.h to the headers list The dependency was missing. Signed-off-by: Dmitry V. Levin Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 51af531..dace211 100644 --- a/Makefile +++ b/Makefile @@ -281,7 +281,7 @@ LIB_FILE=libgit.a XDIFF_LIB=xdiff/lib.a LIB_H = \ - archive.h blob.h cache.h commit.h csum-file.h delta.h grep.h \ + archive.h blob.h cache.h cache-tree.h commit.h csum-file.h delta.h grep.h \ diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h sideband.h \ run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \ tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \ -- cgit v0.10.2-6-g49f6 From 432e93a16441a1a11aeb8158a634f76c214abb31 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 5 Sep 2007 22:15:21 -0400 Subject: Cleanup unnecessary file modifications in t1400-update-ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kristian Høgsberg pointed out that the two file modifications we were doing during the 'creating initial files' step are not even used within the test suite. This was actually confusing as we do not even need these changes for the tests to pass. All that really matters here is the specific commit dates are used so that these appear in the branch's reflog, and that the dates are different so that the branch will update when asked and the reflog entry is also updated. There is no need for the file modification. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index c4c0dfa..ce045b2 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -198,11 +198,9 @@ test_expect_success \ GIT_AUTHOR_DATE="2005-05-26 23:41" \ GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a && h_OTHER=$(git rev-parse --verify HEAD) && - echo FIXED >F && GIT_AUTHOR_DATE="2005-05-26 23:44" \ GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend && h_FIXED=$(git rev-parse --verify HEAD) && - echo TEST+FIXED >F && echo Merged initial commit and a later commit. >M && echo $h_TEST >.git/MERGE_HEAD && GIT_AUTHOR_DATE="2005-05-26 23:45" \ -- cgit v0.10.2-6-g49f6 From 4e560158c6de154fafab9fc3f6028d9edcc53e6b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 6 Sep 2007 00:44:08 -0400 Subject: Include a git-push example for creating a remote branch Many users get confused when `git push origin master:foo` works when foo already exists on the remote repository but are confused when foo doesn't exist as a branch and this form does not create the branch foo. This new example highlights the trick of including refs/heads/ in front of the desired branch name to create a branch. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 0dd9caf..7b8e075 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -117,6 +117,12 @@ git push origin master:satellite/master:: the ref that matches `satellite/master` (most likely, it would be `refs/remotes/satellite/master`) in `origin` repository with it. +git push origin master:refs/heads/experimental:: + Create the branch `experimental` in the `origin` repository + by copying the current `master` branch. This form is usually + needed to create a new branch in the remote repository as + there is no `experimental` branch to match. + Author ------ Written by Junio C Hamano , later rewritten in C -- cgit v0.10.2-6-g49f6