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>
This commit is contained in:
committed by
Junio C Hamano
parent
564d0252ca
commit
568459bf5e
@@ -222,6 +222,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));
|
||||
@@ -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,
|
||||
&size);
|
||||
if (!contents)
|
||||
die("object %s disappeared", oid_to_hex(oid));
|
||||
|
||||
if (use_mailmap) {
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -482,6 +486,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user