diff mbox series

[15/44] builtin/receive-pack: detect when the server doesn't support our hash

Message ID 20200513005424.81369-16-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series SHA-256 part 2/3: protocol functionality | expand

Commit Message

brian m. carlson May 13, 2020, 12:53 a.m. UTC
Detect when the server doesn't support our hash algorithm and abort.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/receive-pack.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Martin Ă…gren May 16, 2020, 10:41 a.m. UTC | #1
On Wed, 13 May 2020 at 02:56, brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> +                       const char *hash;
> +                       int len = 0;

Micronit: These new variables are used in tandem. I could see these as
"NULL, 0" or both uninitialized, but this is a mixture. That's a really
small nit, of course. (Maybe you needed to fight a compiler warning?)

> +                       hash = parse_feature_value(feature_list, "object-format", &len, NULL);
> +                       if (!hash) {
> +                               hash = hash_algos[GIT_HASH_SHA1].name;
> +                               len = strlen(hash);
> +                       }
> +                       if (xstrncmpz(the_hash_algo->name, hash, len))
> +                               die("error: unsupported object format '%s'", hash);

Ok, this is a familiar pattern by now: if we get nothing, behave as if
we got SHA-1.


Martin
diff mbox series

Patch

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index a4159b559e..8755fa2463 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1624,6 +1624,8 @@  static struct command *read_head_info(struct packet_reader *reader,
 		linelen = strlen(reader->line);
 		if (linelen < reader->pktlen) {
 			const char *feature_list = reader->line + linelen + 1;
+			const char *hash;
+			int len = 0;
 			if (parse_feature_request(feature_list, "report-status"))
 				report_status = 1;
 			if (parse_feature_request(feature_list, "side-band-64k"))
@@ -1636,6 +1638,13 @@  static struct command *read_head_info(struct packet_reader *reader,
 			if (advertise_push_options
 			    && parse_feature_request(feature_list, "push-options"))
 				use_push_options = 1;
+			hash = parse_feature_value(feature_list, "object-format", &len, NULL);
+			if (!hash) {
+				hash = hash_algos[GIT_HASH_SHA1].name;
+				len = strlen(hash);
+			}
+			if (xstrncmpz(the_hash_algo->name, hash, len))
+				die("error: unsupported object format '%s'", hash);
 		}
 
 		if (!strcmp(reader->line, "push-cert")) {