Skip to content

Commit 235ac40

Browse files
author
Linus Torvalds
committed
Don't add references to objects we couldn't find.
That would SIGSEGV.
1 parent c35dfe8 commit 235ac40

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

commit.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ int parse_commit(struct commit *item)
5959
sha1_to_hex(item->object.sha1));
6060
get_sha1_hex(bufptr + 5, parent);
6161
item->tree = lookup_tree(parent);
62-
add_ref(&item->object, &item->tree->object);
62+
if (item->tree)
63+
add_ref(&item->object, &item->tree->object);
6364
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
6465
while (!memcmp(bufptr, "parent ", 7) &&
6566
!get_sha1_hex(bufptr + 7, parent)) {
6667
struct commit *new_parent = lookup_commit(parent);
67-
commit_list_insert(new_parent, &item->parents);
68-
add_ref(&item->object, &new_parent->object);
68+
if (new_parent) {
69+
commit_list_insert(new_parent, &item->parents);
70+
add_ref(&item->object, &new_parent->object);
71+
}
6972
bufptr += 48;
7073
}
7174
item->date = parse_commit_date(bufptr);

tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ int parse_tree(struct tree *item)
137137
entry->item.blob = lookup_blob(file_sha1);
138138
obj = &entry->item.blob->object;
139139
}
140-
add_ref(&item->object, obj);
140+
if (obj)
141+
add_ref(&item->object, obj);
141142

142143
*list_p = entry;
143144
list_p = &entry->next;

0 commit comments

Comments
 (0)