threads / patch / 32555

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

Subject: [PATCH] upload-pack: only accept commits from "shallow" line

## tl;dr

2 messages between Jan 8, 2013 and Jan 8, 2013. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Nguyễn Thái Ngọc Duy· Jan 8, 2013, 11:32 UTC · lore

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.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 upload-pack.c | 2 ++
 1 file changed, 2 insertions(+)
Show changes to upload-pack.c +2 −0
diff --git a/upload-pack.c b/upload-pack.c
index 6142421..95d8313 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -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;
-- 
1.8.0.rc0.19.g7bbb31d
Junio C Hamano· Jan 8, 2013, 17:27 UTC · re: Nguyễn Thái Ngọc Duy · lore

Re: [PATCH] upload-pack: only accept commits from "shallow" line

Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 10 quoted lines
> 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.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---

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

Show 16 quoted lines
>  upload-pack.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/upload-pack.c b/upload-pack.c
> index 6142421..95d8313 100644
> --- a/upload-pack.c
> +++ b/upload-pack.c
> @@ -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;

← back to recent threads