@matheusbsbs / matheus-bagliano / commits / bb095d0875
Fork 0

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

Detect when the server doesn't support our hash algorithm and abort. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 25, 2020 at 19:59 UTC bb095d087557b9ded2245270d3fac64ddc774af6
1 file changed +9
builtin/receive-pack.c
+9
@@ -1624,6 +1624,8 @@ static struct command *read_head_info(struct packet_reader *reader,
1624 linelen = strlen(reader->line);
1625 if (linelen < reader->pktlen) {
1626 const char *feature_list = reader->line + linelen + 1;
1627 + const char *hash = NULL;
1628 + int len = 0;
1629 if (parse_feature_request(feature_list, "report-status"))
1630 report_status = 1;
1631 if (parse_feature_request(feature_list, "side-band-64k"))
@@ -1636,6 +1638,13 @@ static struct command *read_head_info(struct packet_reader *reader,
1638 if (advertise_push_options
1639 && parse_feature_request(feature_list, "push-options"))
1640 use_push_options = 1;
1641 + hash = parse_feature_value(feature_list, "object-format", &len, NULL);
1642 + if (!hash) {
1643 + hash = hash_algos[GIT_HASH_SHA1].name;
1644 + len = strlen(hash);
1645 + }
1646 + if (xstrncmpz(the_hash_algo->name, hash, len))
1647 + die("error: unsupported object format '%s'", hash);
1648 }
1649
1650 if (!strcmp(reader->line, "push-cert")) {