Skip to content

Commit c59ba68

Browse files
committed
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()`
2 parents e864023 + 568459b commit c59ba68

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

bisect.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static void show_list(const char *debug, int counted, int nr,
158158
const char *subject_start;
159159
int subject_len;
160160

161+
if (!buf)
162+
die(_("unable to read %s"), oid_to_hex(&commit->object.oid));
163+
161164
fprintf(stderr, "%c%c%c ",
162165
(commit_flags & TREESAME) ? ' ' : 'T',
163166
(commit_flags & UNINTERESTING) ? 'U' : ' ',

builtin/cat-file.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
221221
&type,
222222
&size);
223223
const char *target;
224+
225+
if (!buffer)
226+
die(_("unable to read %s"), oid_to_hex(&oid));
227+
224228
if (!skip_prefix(buffer, "object ", &target) ||
225229
get_oid_hex(target, &blob_oid))
226230
die("%s not a valid tag", oid_to_hex(&oid));
@@ -416,15 +420,15 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
416420

417421
contents = repo_read_object_file(the_repository, oid, &type,
418422
&size);
423+
if (!contents)
424+
die("object %s disappeared", oid_to_hex(oid));
419425

420426
if (use_mailmap) {
421427
size_t s = size;
422428
contents = replace_idents_using_mailmap(contents, &s);
423429
size = cast_size_t_to_ulong(s);
424430
}
425431

426-
if (!contents)
427-
die("object %s disappeared", oid_to_hex(oid));
428432
if (type != data->type)
429433
die("object %s changed type!?", oid_to_hex(oid));
430434
if (data->info.sizep && size != data->size && !use_mailmap)
@@ -481,6 +485,8 @@ static void batch_object_write(const char *obj_name,
481485

482486
buf = repo_read_object_file(the_repository, &data->oid, &data->type,
483487
&data->size);
488+
if (!buf)
489+
die(_("unable to read %s"), oid_to_hex(&data->oid));
484490
buf = replace_idents_using_mailmap(buf, &s);
485491
data->size = cast_size_t_to_ulong(s);
486492

builtin/grep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ static int grep_cache(struct grep_opt *opt,
571571

572572
data = repo_read_object_file(the_repository, &ce->oid,
573573
&type, &size);
574+
if (!data)
575+
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
574576
init_tree_desc(&tree, data, size);
575577

576578
hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);

builtin/notes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,11 @@ static int append_edit(int argc, const char **argv, const char *prefix)
716716
struct strbuf buf = STRBUF_INIT;
717717
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
718718

719-
if (prev_buf && size)
719+
if (!prev_buf)
720+
die(_("unable to read %s"), oid_to_hex(note));
721+
if (size)
720722
strbuf_add(&buf, prev_buf, size);
721-
if (d.buf.len && prev_buf && size)
723+
if (d.buf.len && size)
722724
append_separator(&buf);
723725
strbuf_insert(&d.buf, 0, buf.buf, buf.len);
724726

combine-diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ static char *grab_blob(struct repository *r,
337337
free_filespec(df);
338338
} else {
339339
blob = repo_read_object_file(r, oid, &type, size);
340+
if (!blob)
341+
die(_("unable to read %s"), oid_to_hex(oid));
340342
if (type != OBJ_BLOB)
341343
die("object '%s' is not a blob!", oid_to_hex(oid));
342344
}

rerere.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ static int handle_cache(struct index_state *istate,
973973
mmfile[i].ptr = repo_read_object_file(the_repository,
974974
&ce->oid, &type,
975975
&size);
976+
if (!mmfile[i].ptr)
977+
die(_("unable to read %s"),
978+
oid_to_hex(&ce->oid));
976979
mmfile[i].size = size;
977980
}
978981
}

0 commit comments

Comments
 (0)