mirror of
https://github.com/git/git
synced 2024-08-28 20:20:07 +00:00
fsck-cache: fix segfault on nonexistent referenced object
Noted by Frank Sorenson and Petr Baudis, patch rewritten by me.
This commit is contained in:
parent
de809dbbce
commit
7c4d07c7cc
12
fsck-cache.c
12
fsck-cache.c
|
@ -296,7 +296,7 @@ static int fsck_dir(int i, char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_sha1_reference(const char *path)
|
static int read_sha1_reference(const char *path)
|
||||||
{
|
{
|
||||||
char hexname[60];
|
char hexname[60];
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
@ -304,19 +304,23 @@ static void read_sha1_reference(const char *path)
|
||||||
struct object *obj;
|
struct object *obj;
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
len = read(fd, hexname, sizeof(hexname));
|
len = read(fd, hexname, sizeof(hexname));
|
||||||
close(fd);
|
close(fd);
|
||||||
if (len < 40)
|
if (len < 40)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if (get_sha1_hex(hexname, sha1) < 0)
|
if (get_sha1_hex(hexname, sha1) < 0)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
obj = lookup_object(sha1);
|
obj = lookup_object(sha1);
|
||||||
|
if (!obj)
|
||||||
|
return error("%s: invalid sha1 pointer %.40s", path, hexname);
|
||||||
|
|
||||||
obj->used = 1;
|
obj->used = 1;
|
||||||
mark_reachable(obj, REACHABLE);
|
mark_reachable(obj, REACHABLE);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void find_file_objects(const char *base, const char *name)
|
static void find_file_objects(const char *base, const char *name)
|
||||||
|
|
Loading…
Reference in a new issue