Always check the return value of `repo_read_object_file()`
There are a couple of places in Git's source code where the return value is not checked. As a consequence, they are susceptible to segmentation faults. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
564d0252ca
commit
568459bf5e
3
bisect.c
3
bisect.c
|
@ -159,6 +159,9 @@ static void show_list(const char *debug, int counted, int nr,
|
||||||
const char *subject_start;
|
const char *subject_start;
|
||||||
int subject_len;
|
int subject_len;
|
||||||
|
|
||||||
|
if (!buf)
|
||||||
|
die(_("unable to read %s"), oid_to_hex(&commit->object.oid));
|
||||||
|
|
||||||
fprintf(stderr, "%c%c%c ",
|
fprintf(stderr, "%c%c%c ",
|
||||||
(commit_flags & TREESAME) ? ' ' : 'T',
|
(commit_flags & TREESAME) ? ' ' : 'T',
|
||||||
(commit_flags & UNINTERESTING) ? 'U' : ' ',
|
(commit_flags & UNINTERESTING) ? 'U' : ' ',
|
||||||
|
|
|
@ -222,6 +222,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||||
&type,
|
&type,
|
||||||
&size);
|
&size);
|
||||||
const char *target;
|
const char *target;
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
|
die(_("unable to read %s"), oid_to_hex(&oid));
|
||||||
|
|
||||||
if (!skip_prefix(buffer, "object ", &target) ||
|
if (!skip_prefix(buffer, "object ", &target) ||
|
||||||
get_oid_hex(target, &blob_oid))
|
get_oid_hex(target, &blob_oid))
|
||||||
die("%s not a valid tag", oid_to_hex(&oid));
|
die("%s not a valid tag", oid_to_hex(&oid));
|
||||||
|
@ -417,6 +421,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
|
||||||
|
|
||||||
contents = repo_read_object_file(the_repository, oid, &type,
|
contents = repo_read_object_file(the_repository, oid, &type,
|
||||||
&size);
|
&size);
|
||||||
|
if (!contents)
|
||||||
|
die("object %s disappeared", oid_to_hex(oid));
|
||||||
|
|
||||||
if (use_mailmap) {
|
if (use_mailmap) {
|
||||||
size_t s = size;
|
size_t s = size;
|
||||||
|
@ -424,8 +430,6 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
|
||||||
size = cast_size_t_to_ulong(s);
|
size = cast_size_t_to_ulong(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contents)
|
|
||||||
die("object %s disappeared", oid_to_hex(oid));
|
|
||||||
if (type != data->type)
|
if (type != data->type)
|
||||||
die("object %s changed type!?", oid_to_hex(oid));
|
die("object %s changed type!?", oid_to_hex(oid));
|
||||||
if (data->info.sizep && size != data->size && !use_mailmap)
|
if (data->info.sizep && size != data->size && !use_mailmap)
|
||||||
|
@ -482,6 +486,8 @@ static void batch_object_write(const char *obj_name,
|
||||||
|
|
||||||
buf = repo_read_object_file(the_repository, &data->oid, &data->type,
|
buf = repo_read_object_file(the_repository, &data->oid, &data->type,
|
||||||
&data->size);
|
&data->size);
|
||||||
|
if (!buf)
|
||||||
|
die(_("unable to read %s"), oid_to_hex(&data->oid));
|
||||||
buf = replace_idents_using_mailmap(buf, &s);
|
buf = replace_idents_using_mailmap(buf, &s);
|
||||||
data->size = cast_size_t_to_ulong(s);
|
data->size = cast_size_t_to_ulong(s);
|
||||||
|
|
||||||
|
|
|
@ -575,6 +575,8 @@ static int grep_cache(struct grep_opt *opt,
|
||||||
|
|
||||||
data = repo_read_object_file(the_repository, &ce->oid,
|
data = repo_read_object_file(the_repository, &ce->oid,
|
||||||
&type, &size);
|
&type, &size);
|
||||||
|
if (!data)
|
||||||
|
die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
|
||||||
init_tree_desc(&tree, data, size);
|
init_tree_desc(&tree, data, size);
|
||||||
|
|
||||||
hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);
|
hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);
|
||||||
|
|
|
@ -718,9 +718,11 @@ static int append_edit(int argc, const char **argv, const char *prefix)
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
|
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
|
||||||
|
|
||||||
if (prev_buf && size)
|
if (!prev_buf)
|
||||||
|
die(_("unable to read %s"), oid_to_hex(note));
|
||||||
|
if (size)
|
||||||
strbuf_add(&buf, prev_buf, size);
|
strbuf_add(&buf, prev_buf, size);
|
||||||
if (d.buf.len && prev_buf && size)
|
if (d.buf.len && size)
|
||||||
append_separator(&buf);
|
append_separator(&buf);
|
||||||
strbuf_insert(&d.buf, 0, buf.buf, buf.len);
|
strbuf_insert(&d.buf, 0, buf.buf, buf.len);
|
||||||
|
|
||||||
|
|
|
@ -338,6 +338,8 @@ static char *grab_blob(struct repository *r,
|
||||||
free_filespec(df);
|
free_filespec(df);
|
||||||
} else {
|
} else {
|
||||||
blob = repo_read_object_file(r, oid, &type, size);
|
blob = repo_read_object_file(r, oid, &type, size);
|
||||||
|
if (!blob)
|
||||||
|
die(_("unable to read %s"), oid_to_hex(oid));
|
||||||
if (type != OBJ_BLOB)
|
if (type != OBJ_BLOB)
|
||||||
die("object '%s' is not a blob!", oid_to_hex(oid));
|
die("object '%s' is not a blob!", oid_to_hex(oid));
|
||||||
}
|
}
|
||||||
|
|
3
rerere.c
3
rerere.c
|
@ -975,6 +975,9 @@ static int handle_cache(struct index_state *istate,
|
||||||
mmfile[i].ptr = repo_read_object_file(the_repository,
|
mmfile[i].ptr = repo_read_object_file(the_repository,
|
||||||
&ce->oid, &type,
|
&ce->oid, &type,
|
||||||
&size);
|
&size);
|
||||||
|
if (!mmfile[i].ptr)
|
||||||
|
die(_("unable to read %s"),
|
||||||
|
oid_to_hex(&ce->oid));
|
||||||
mmfile[i].size = size;
|
mmfile[i].size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue