diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2024-02-23 08:34:23 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-02-23 10:19:40 -0800 |
commit | aa9f618909d30e3f0c7181243e89a81220507e6e (patch) | |
tree | eba8780bfd3266fc0fc9371a0e9024d92d04b036 /builtin/commit.c | |
parent | 98c6d16d6746059dc1e1183f8f8366eef2a41eff (diff) |
Always check `parse_tree*()`'s return value
Otherwise we may easily run into serious crashes: For example, if we run
`init_tree_desc()` directly after a failed `parse_tree()`, we are
accessing uninitialized data or trying to dereference `NULL`.
Note that the `parse_tree()` function already takes care of showing an
error message. The `parse_tree_indirectly()` and
`repo_get_commit_tree()` functions do not, therefore those latter call
sites need to show a useful error message while the former do not.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 781af2e206..0723f06de7 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -339,7 +339,8 @@ static void create_base_index(const struct commit *current_head) tree = parse_tree_indirect(¤t_head->object.oid); if (!tree) die(_("failed to unpack HEAD tree object")); - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts)) exit(128); /* We've already reported the error, finish dying */ |