Skip to content

Commit 3548726

Browse files
rscharfegitster
authored andcommitted
get-tar-commit-id: parse comment record
Parse pax comment records properly and get rid of magic numbers for acceptable comment length. This simplifies a later change to handle longer hashes. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9539978 commit 3548726

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

builtin/get-tar-commit-id.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
2121
char *content = buffer + RECORDSIZE;
2222
const char *comment;
2323
ssize_t n;
24+
long len;
25+
char *end;
2426

2527
if (argc != 1)
2628
usage(builtin_get_tar_commit_id_usage);
@@ -32,10 +34,17 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
3234
die_errno("git get-tar-commit-id: EOF before reading tar header");
3335
if (header->typeflag[0] != 'g')
3436
return 1;
35-
if (!skip_prefix(content, "52 comment=", &comment))
37+
38+
len = strtol(content, &end, 10);
39+
if (errno == ERANGE || end == content || len < 0)
40+
return 1;
41+
if (!skip_prefix(end, " comment=", &comment))
42+
return 1;
43+
len -= comment - content;
44+
if (len != GIT_SHA1_HEXSZ + 1)
3645
return 1;
3746

38-
if (write_in_full(1, comment, 41) < 0)
47+
if (write_in_full(1, comment, len) < 0)
3948
die_errno("git get-tar-commit-id: write error");
4049

4150
return 0;

0 commit comments

Comments
 (0)