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 15, 2005 at 17:10 UTC
48bc2fb0cd9ca05005c2062c3493e62e13593f55
3 files changed
+16
clone-pack.c
+6
@@ -34,6 +34,12 @@ static void write_one_ref(struct ref *ref)
34
int fd;
35
char *hex;
36
37
+ if (!strncmp(ref->name, "refs/", 5) &&
38
+ check_ref_format(ref->name + 5)) {
39
+ error("refusing to create funny ref '%s' locally", ref->name);
40
+ return;
41
+ }
42
+
43
if (safe_create_leading_directories(path))
44
die("unable to create leading directory for %s", ref->name);
45
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);