Skip to content

Commit

Permalink
fsck-cache: fix segfault on nonexistent referenced object
Browse files Browse the repository at this point in the history
Noted by Frank Sorenson and Petr Baudis, patch rewritten by me.
  • Loading branch information
Linus Torvalds committed May 20, 2005
1 parent de809db commit 7c4d07c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions fsck-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,31 @@ static int fsck_dir(int i, char *path)
return 0;
}

static void read_sha1_reference(const char *path)
static int read_sha1_reference(const char *path)
{
char hexname[60];
unsigned char sha1[20];
int fd = open(path, O_RDONLY), len;
struct object *obj;

if (fd < 0)
return;
return -1;

len = read(fd, hexname, sizeof(hexname));
close(fd);
if (len < 40)
return;
return -1;

if (get_sha1_hex(hexname, sha1) < 0)
return;
return -1;

obj = lookup_object(sha1);
if (!obj)
return error("%s: invalid sha1 pointer %.40s", path, hexname);

obj->used = 1;
mark_reachable(obj, REACHABLE);
return 0;
}

static void find_file_objects(const char *base, const char *name)
Expand Down

0 comments on commit 7c4d07c

Please sign in to comment.