diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-02-14 15:36:06 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-02-14 15:36:06 -0800 |
| commit | c59ba68ea7d1b4614fa964403a6c662dca0dd212 (patch) | |
| tree | ba54ccb735bf678d57407f9053f179867cc038f5 /builtin/cat-file.c | |
| parent | Merge branch 'rs/receive-pack-remove-find-header' (diff) | |
| parent | Always check the return value of `repo_read_object_file()` (diff) | |
| download | git-c59ba68ea7d1b4614fa964403a6c662dca0dd212.tar.gz git-c59ba68ea7d1b4614fa964403a6c662dca0dd212.zip | |
Merge branch 'js/check-null-from-read-object-file'
The code paths that call repo_read_object_file() have been
tightened to react to errors.
* js/check-null-from-read-object-file:
Always check the return value of `repo_read_object_file()`
Diffstat (limited to 'builtin/cat-file.c')
| -rw-r--r-- | builtin/cat-file.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 7d4899348a..bbf851138e 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -221,6 +221,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, &type, &size); const char *target; + + if (!buffer) + die(_("unable to read %s"), oid_to_hex(&oid)); + if (!skip_prefix(buffer, "object ", &target) || get_oid_hex(target, &blob_oid)) die("%s not a valid tag", oid_to_hex(&oid)); @@ -416,6 +420,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d contents = repo_read_object_file(the_repository, oid, &type, &size); + if (!contents) + die("object %s disappeared", oid_to_hex(oid)); if (use_mailmap) { size_t s = size; @@ -423,8 +429,6 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d size = cast_size_t_to_ulong(s); } - if (!contents) - die("object %s disappeared", oid_to_hex(oid)); if (type != data->type) die("object %s changed type!?", oid_to_hex(oid)); if (data->info.sizep && size != data->size && !use_mailmap) @@ -481,6 +485,8 @@ static void batch_object_write(const char *obj_name, buf = repo_read_object_file(the_repository, &data->oid, &data->type, &data->size); + if (!buf) + die(_("unable to read %s"), oid_to_hex(&data->oid)); buf = replace_idents_using_mailmap(buf, &s); data->size = cast_size_t_to_ulong(s); |
