Refuse to create funny refs in clone-pack, git-fetch and receive-pack.
Using git-check-ref-format, make sure we do not create refs with funny names when cloning from elsewhere (clone-pack), fast forwarding local heads (git-fetch), or somebody pushes into us (receive-pack). Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 13, 2005 at 18:57 UTC
d8a1deecc6ef37728b951eaba051deb7e0a38af8
3 files changed
+16
clone-pack.c
+6
@@ -36,6 +36,12 @@ static void write_one_ref(struct ref *ref)
36
int fd;
37
char *hex;
38
39
+ if (!strncmp(ref->name, "refs/", 5) &&
40
+ check_ref_format(ref->name + 5)) {
41
+ error("refusing to create funny ref '%s' locally", ref->name);
42
+ return;
43
+ }
44
+
45
if (safe_create_leading_directories(path))
46
die("unable to create leading directory for %s", ref->name);
47
fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
git-parse-remote.sh
+6
@@ -94,6 +94,12 @@ canon_refs_list_for_fetch () {
94
heads/* | tags/* ) local="refs/$local" ;;
95
*) local="refs/heads/$local" ;;
96
esac
97
+
98
+ if local_ref_name=$(expr "$local" : 'refs/\(.*\)')
99
+ then
100
+ git-check-ref-format "$local_ref_name" ||
101
+ die "* refusing to create funny ref '$local_ref_name' locally"
102
+ fi
103
echo "${dot_prefix}${force}${remote}:${local}"
104
dot_prefix=.
105
done
receive-pack.c
+4
@@ -95,6 +95,10 @@ static int update(const char *name,
95
char new_hex[60], *old_hex, *lock_name;
96
int newfd, namelen, written;
97
98
+ if (!strncmp(name, "refs/", 5) && check_ref_format(name + 5))
99
+ return error("refusing to create funny ref '%s' locally",
100
+ name);
101
+
102
namelen = strlen(name);
103
lock_name = xmalloc(namelen + 10);
104
memcpy(lock_name, name, namelen);