builtin/get-tar-commit-id: make hash size independent

To make this code independent of the hash size, verify that the length
of the comment is equal to that of any supported hash algorithm.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson 2019-02-19 00:05:19 +00:00 коммит произвёл Junio C Hamano
Родитель 3548726cd7
Коммит 87003d2c94
1 изменённых файлов: 2 добавлений и 1 удалений

Просмотреть файл

@ -41,7 +41,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
if (!skip_prefix(end, " comment=", &comment))
return 1;
len -= comment - content;
if (len != GIT_SHA1_HEXSZ + 1)
if (len < 1 || !(len % 2) ||
hash_algo_by_length((len - 1) / 2) == GIT_HASH_UNKNOWN)
return 1;
if (write_in_full(1, comment, len) < 0)