Skip to contentSkip to conversation

upload-pack: only accept commits from "shallow" line

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 upload-pack: only accept commits from "shallow" line

We only allow cuts at commits, not arbitrary objects. upload-pack will fail eventually in register_shallow if a non-commit is given with a generic error "Object %s is a %s, not a commit". Check it early and give a more accurate error.

This should never show up in an ordinary session. It's for buggy clients, or when the user manually edits .git/shallow.

---
 upload-pack.c | 2 ++
 1 file changed, 2 insertions(+)
upload-pack.c +2 -0
index 6142421..95d8313 100644
@@ -603,6 +603,8 @@ static void receive_needs(void)
 			object = parse_object(sha1);
 			if (!object)
 				die("did not find object for %s", line);
+			if (object->type != OBJ_COMMIT)
+				die("invalid shallow object %s", sha1_to_hex(sha1));
 			object->flags |= CLIENT_SHALLOW;
 			add_object_array(object, NULL, &shallows);
 			continue;
Signature · 1 line
1.8.0.rc0.19.g7bbb31d
#1 lore raw
Quoted 10 lines · Nguyễn Thái Ngọc Duy

We only allow cuts at commits, not arbitrary objects. upload-pack will fail eventually in register_shallow if a non-commit is given with a generic error "Object %s is a %s, not a commit". Check it early and give a more accurate error.

This should never show up in an ordinary session. It's for buggy clients, or when the user manually edits .git/shallow.

---

Thanks. I agree with you that while this is not wrong per-se, this will not matter in real life.

Quoted 16 lines
 upload-pack.c | 2 ++
 1 file changed, 2 insertions(+)
upload-pack.c +2 -0
index 6142421..95d8313 100644
@@ -603,6 +603,8 @@ static void receive_needs(void)
 			object = parse_object(sha1);
 			if (!object)
 				die("did not find object for %s", line);
+			if (object->type != OBJ_COMMIT)
+				die("invalid shallow object %s", sha1_to_hex(sha1));
 			object->flags |= CLIENT_SHALLOW;
 			add_object_array(object, NULL, &shallows);
 			continue;