Skip to content

Commit cc0ea7c

Browse files
peffgitster
authored andcommitted
cat-file: handle NULL object_context.path
Commit dc944b6 (get_sha1_with_context: dynamically allocate oc->path, 2017-05-19) changed the rules that callers must follow for seeing if we parsed a path in the object name. The rules switched from "check if the oc.path buffer is empty" to "check if the oc.path pointer is NULL". But that commit forgot to update some sites in cat_one_file(), meaning we might dereference a NULL pointer. You can see this by making a path-aware request like --textconv without specifying --path, and giving an object name that doesn't have a path in it. Like: git cat-file --textconv HEAD which will reliably segfault. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30d005c commit cc0ea7c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
9494
return !has_object_file(&oid);
9595

9696
case 'w':
97-
if (!path[0])
97+
if (!path)
9898
die("git cat-file --filters %s: <object> must be "
9999
"<sha1:path>", obj_name);
100100

@@ -104,7 +104,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
104104
break;
105105

106106
case 'c':
107-
if (!path[0])
107+
if (!path)
108108
die("git cat-file --textconv %s: <object> must be <sha1:path>",
109109
obj_name);
110110

t/t8010-cat-file-filters.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ test_expect_success '--path=<path> complains without --textconv/--filters' '
5151
grep "path.*needs.*filters" err
5252
'
5353

54+
test_expect_success '--textconv/--filters complain without path' '
55+
test_must_fail git cat-file --textconv HEAD &&
56+
test_must_fail git cat-file --filters HEAD
57+
'
58+
5459
test_expect_success 'cat-file --textconv --batch works' '
5560
sha1=$(git rev-parse -q --verify HEAD:world.txt) &&
5661
test_config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" &&

0 commit comments

Comments
 (0)