fix a null-pointer deref in 'got fetch -d'; reported by Omar Polo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
diff --git a/got/got.c b/got/got.c
index 5f3984d..b1b444c 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2020,8 +2020,11 @@ delete_missing_refs(struct got_pathlist_head *their_refs,
TAILQ_FOREACH(re, &my_refs, entry) {
const char *refname = got_ref_get_name(re->ref);
+ const char *their_refname;
- if (!remote->mirror_references) {
+ if (remote->mirror_references) {
+ their_refname = refname;
+ } else {
if (strncmp(refname, remote_namespace,
strlen(remote_namespace)) == 0) {
if (strcmp(refname + strlen(remote_namespace),
@@ -2034,17 +2037,19 @@ delete_missing_refs(struct got_pathlist_head *their_refs,
}
} else if (strncmp(refname, "refs/tags/", 10) != 0)
continue;
- }
+ their_refname = local_refname;
+ }
+
TAILQ_FOREACH(pe, their_refs, entry) {
- if (strcmp(local_refname, pe->path) == 0)
+ if (strcmp(their_refname, pe->path) == 0)
break;
}
if (pe != NULL)
continue;
TAILQ_FOREACH(pe, their_symrefs, entry) {
- if (strcmp(local_refname, pe->path) == 0)
+ if (strcmp(their_refname, pe->path) == 0)
break;
}
if (pe != NULL)
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index e058738..5b536e8 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -509,6 +509,102 @@ test_fetch_delete_branch() {
}
+test_fetch_delete_branch_mirror() {
+ local testroot=`test_init fetch_delete_branch_mirror`
+ local testurl=ssh://127.0.0.1/$testroot
+ local commit_id=`git_show_head $testroot/repo`
+
+ got branch -r $testroot/repo -c $commit_id foo
+ got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
+ got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
+ local tag_id=`got ref -r $testroot/repo -l \
+ | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
+
+ got clone -a -m -q $testurl/repo $testroot/repo-clone
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got clone command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got ref -l -r $testroot/repo-clone > $testroot/stdout
+
+ echo "HEAD: refs/heads/master" > $testroot/stdout.expected
+ echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ # refs/hoo/boo/zoo is missing because it is outside of refs/heads
+ echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got branch -r $testroot/repo -d foo >/dev/null
+
+ got fetch -q -r $testroot/repo-clone
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got fetch command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got ref -l -r $testroot/repo-clone > $testroot/stdout
+
+ echo "HEAD: refs/heads/master" > $testroot/stdout.expected
+ echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ # refs/hoo/boo/zoo is missing because it is outside of refs/heads
+ echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got fetch command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo -n > $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got ref -l -r $testroot/repo-clone > $testroot/stdout
+
+ echo "HEAD: refs/heads/master" > $testroot/stdout.expected
+ # refs/heads/foo is now deleted
+ echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ # refs/hoo/boo/zoo is missing because it is outside of refs/heads
+ echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
+
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+
+}
+
test_fetch_update_tag() {
local testroot=`test_init fetch_update_tag`
local testurl=ssh://127.0.0.1/$testroot
@@ -1191,6 +1287,7 @@ run_test test_fetch_branch
run_test test_fetch_all
run_test test_fetch_empty_packfile
run_test test_fetch_delete_branch
+run_test test_fetch_delete_branch_mirror
run_test test_fetch_update_tag
run_test test_fetch_reference
run_test test_fetch_replace_symref