Make "parse_commit()" be a lot more careful
This was brought on by a bad tree of Thomas Gleixner, where some bogus commit objects weren't warned about properly Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
f315724431
commit
f7cc77d78b
16
commit.c
16
commit.c
@ -93,22 +93,28 @@ static unsigned long parse_commit_date(const char *buf)
|
|||||||
|
|
||||||
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
|
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
|
||||||
{
|
{
|
||||||
void *bufptr = buffer;
|
char *bufptr = buffer;
|
||||||
unsigned char parent[20];
|
unsigned char parent[20];
|
||||||
struct commit_list **pptr;
|
struct commit_list **pptr;
|
||||||
|
|
||||||
if (item->object.parsed)
|
if (item->object.parsed)
|
||||||
return 0;
|
return 0;
|
||||||
item->object.parsed = 1;
|
item->object.parsed = 1;
|
||||||
get_sha1_hex(bufptr + 5, parent);
|
if (memcmp(bufptr, "tree ", 5))
|
||||||
|
return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
|
||||||
|
if (get_sha1_hex(bufptr + 5, parent) < 0)
|
||||||
|
return error("bad tree pointer in commit %s\n", sha1_to_hex(item->object.sha1));
|
||||||
item->tree = lookup_tree(parent);
|
item->tree = lookup_tree(parent);
|
||||||
if (item->tree)
|
if (item->tree)
|
||||||
add_ref(&item->object, &item->tree->object);
|
add_ref(&item->object, &item->tree->object);
|
||||||
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
|
bufptr += 46; /* "tree " + "hex sha1" + "\n" */
|
||||||
pptr = &item->parents;
|
pptr = &item->parents;
|
||||||
while (!memcmp(bufptr, "parent ", 7) &&
|
while (!memcmp(bufptr, "parent ", 7)) {
|
||||||
!get_sha1_hex(bufptr + 7, parent)) {
|
struct commit *new_parent;
|
||||||
struct commit *new_parent = lookup_commit(parent);
|
|
||||||
|
if (get_sha1_hex(bufptr + 7, parent) || bufptr[47] != '\n')
|
||||||
|
return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
|
||||||
|
new_parent = lookup_commit(parent);
|
||||||
if (new_parent) {
|
if (new_parent) {
|
||||||
pptr = &commit_list_insert(new_parent, pptr)->next;
|
pptr = &commit_list_insert(new_parent, pptr)->next;
|
||||||
add_ref(&item->object, &new_parent->object);
|
add_ref(&item->object, &new_parent->object);
|
||||||
|
Loading…
Reference in New Issue
Block a user