Skip to content

Commit

Permalink
Merge branch 'mk/maint-parse-careful'
Browse files Browse the repository at this point in the history
* mk/maint-parse-careful:
  peel_onion: handle NULL
  check return value from parse_commit() in various functions
  parse_commit: don't fail, if object is NULL
  revision.c: handle tag->tagged == NULL
  reachable.c::process_tree/blob: check for NULL
  process_tag: handle tag->tagged == NULL
  check results of parse_commit in merge_bases
  list-objects.c::process_tree/blob: check for NULL
  reachable.c::add_one_tree: handle NULL from lookup_tree
  mark_blob/tree_uninteresting: check for NULL
  get_sha1_oneline: check return value of parse_object
  read_object_with_reference: don't read beyond the buffer
  • Loading branch information
gitster committed Feb 19, 2008
2 parents 3d51e1b + f73df33 commit ee4f06c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
14 changes: 9 additions & 5 deletions commit.c
Expand Up @@ -311,6 +311,8 @@ int parse_commit(struct commit *item)
unsigned long size;
int ret;

if (!item)
return -1;
if (item->object.parsed)
return 0;
buffer = read_sha1_file(item->object.sha1, &type, &size);
Expand Down Expand Up @@ -385,8 +387,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,

while (parents) {
struct commit *commit = parents->item;
parse_commit(commit);
if (!(commit->object.flags & mark)) {
if (!parse_commit(commit) && !(commit->object.flags & mark)) {
commit->object.flags |= mark;
insert_by_date(commit, list);
}
Expand Down Expand Up @@ -552,8 +553,10 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two)
*/
return commit_list_insert(one, &result);

parse_commit(one);
parse_commit(two);
if (parse_commit(one))
return NULL;
if (parse_commit(two))
return NULL;

one->object.flags |= PARENT1;
two->object.flags |= PARENT2;
Expand Down Expand Up @@ -586,7 +589,8 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two)
parents = parents->next;
if ((p->object.flags & flags) == flags)
continue;
parse_commit(p);
if (parse_commit(p))
return NULL;
p->object.flags |= flags;
insert_by_date(p, &list);
}
Expand Down
4 changes: 4 additions & 0 deletions list-objects.c
Expand Up @@ -18,6 +18,8 @@ static void process_blob(struct rev_info *revs,

if (!revs->blob_objects)
return;
if (!obj)
die("bad blob object");
if (obj->flags & (UNINTERESTING | SEEN))
return;
obj->flags |= SEEN;
Expand Down Expand Up @@ -69,6 +71,8 @@ static void process_tree(struct rev_info *revs,

if (!revs->tree_objects)
return;
if (!obj)
die("bad tree object");
if (obj->flags & (UNINTERESTING | SEEN))
return;
if (parse_tree(tree) < 0)
Expand Down
10 changes: 8 additions & 2 deletions reachable.c
Expand Up @@ -15,6 +15,8 @@ static void process_blob(struct blob *blob,
{
struct object *obj = &blob->object;

if (!blob)
die("bad blob object");
if (obj->flags & SEEN)
return;
obj->flags |= SEEN;
Expand All @@ -39,6 +41,8 @@ static void process_tree(struct tree *tree,
struct name_entry entry;
struct name_path me;

if (!tree)
die("bad tree object");
if (obj->flags & SEEN)
return;
obj->flags |= SEEN;
Expand Down Expand Up @@ -79,7 +83,8 @@ static void process_tag(struct tag *tag, struct object_array *p, const char *nam

if (parse_tag(tag) < 0)
die("bad tag object %s", sha1_to_hex(obj->sha1));
add_object(tag->tagged, p, NULL, name);
if (tag->tagged)
add_object(tag->tagged, p, NULL, name);
}

static void walk_commit_list(struct rev_info *revs)
Expand Down Expand Up @@ -150,7 +155,8 @@ static int add_one_reflog(const char *path, const unsigned char *sha1, int flag,
static void add_one_tree(const unsigned char *sha1, struct rev_info *revs)
{
struct tree *tree = lookup_tree(sha1);
add_pending_object(revs, &tree->object, "");
if (tree)
add_pending_object(revs, &tree->object, "");
}

static void add_cache_tree(struct cache_tree *it, struct rev_info *revs)
Expand Down
8 changes: 8 additions & 0 deletions revision.c
Expand Up @@ -46,6 +46,8 @@ void add_object(struct object *obj,

static void mark_blob_uninteresting(struct blob *blob)
{
if (!blob)
return;
if (blob->object.flags & UNINTERESTING)
return;
blob->object.flags |= UNINTERESTING;
Expand All @@ -57,6 +59,8 @@ void mark_tree_uninteresting(struct tree *tree)
struct name_entry entry;
struct object *obj = &tree->object;

if (!tree)
return;
if (obj->flags & UNINTERESTING)
return;
obj->flags |= UNINTERESTING;
Expand Down Expand Up @@ -173,6 +177,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
struct tag *tag = (struct tag *) object;
if (revs->tag_objects && !(flags & UNINTERESTING))
add_pending_object(revs, object, tag->tag);
if (!tag->tagged)
die("bad tag");
object = parse_object(tag->tagged->sha1);
if (!object)
die("bad object %s", sha1_to_hex(tag->tagged->sha1));
Expand Down Expand Up @@ -685,6 +691,8 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
it = get_reference(revs, arg, sha1, 0);
if (it->type != OBJ_TAG)
break;
if (!((struct tag*)it)->tagged)
return 0;
hashcpy(sha1, ((struct tag*)it)->tagged->sha1);
}
if (it->type != OBJ_COMMIT)
Expand Down
3 changes: 2 additions & 1 deletion sha1_file.c
Expand Up @@ -1943,7 +1943,8 @@ void *read_object_with_reference(const unsigned char *sha1,
}
ref_length = strlen(ref_type);

if (memcmp(buffer, ref_type, ref_length) ||
if (ref_length + 40 > isize ||
memcmp(buffer, ref_type, ref_length) ||
get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
free(buffer);
return NULL;
Expand Down
8 changes: 6 additions & 2 deletions sha1_name.c
Expand Up @@ -494,8 +494,11 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
return error("%.*s: expected %s type, but the object dereferences to %s type",
len, name, typename(expected_type),
typename(o->type));
if (!o)
return -1;
if (!o->parsed)
parse_object(o->sha1);
if (!parse_object(o->sha1))
return -1;
}
}
return 0;
Expand Down Expand Up @@ -620,7 +623,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
unsigned long size;

commit = pop_most_recent_commit(&list, ONELINE_SEEN);
parse_object(commit->object.sha1);
if (!parse_object(commit->object.sha1))
continue;
if (temp_commit_buffer)
free(temp_commit_buffer);
if (commit->buffer)
Expand Down
3 changes: 2 additions & 1 deletion shallow.c
Expand Up @@ -70,7 +70,8 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
cur_depth = *(int *)commit->util;
}
}
parse_commit(commit);
if (parse_commit(commit))
die("invalid commit");
commit->object.flags |= not_shallow_flag;
cur_depth++;
for (p = commit->parents, commit = NULL; p; p = p->next) {
Expand Down
3 changes: 2 additions & 1 deletion upload-pack.c
Expand Up @@ -534,7 +534,8 @@ static void receive_needs(void)
/* make sure the real parents are parsed */
unregister_shallow(object->sha1);
object->parsed = 0;
parse_commit((struct commit *)object);
if (parse_commit((struct commit *)object))
die("invalid commit");
parents = ((struct commit *)object)->parents;
while (parents) {
add_object_array(&parents->item->object,
Expand Down

0 comments on commit ee4f06c

Please sign in to comment.