summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-20 14:49:17 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-20 14:49:17 (GMT)
commit7c4d07c7cc8543f1000639dc19cfaacbc76e5348 (patch)
treecb3820bf24afa1cfee3e082a48e03dc273a70e63
parentde809dbbce497e0d107562615c1d85ff35b4e0c5 (diff)
downloadgit-7c4d07c7cc8543f1000639dc19cfaacbc76e5348.zip
git-7c4d07c7cc8543f1000639dc19cfaacbc76e5348.tar.gz
git-7c4d07c7cc8543f1000639dc19cfaacbc76e5348.tar.bz2
fsck-cache: fix segfault on nonexistent referenced object
Noted by Frank Sorenson and Petr Baudis, patch rewritten by me.
-rw-r--r--fsck-cache.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/fsck-cache.c b/fsck-cache.c
index 32fa5d5..6c65f2b 100644
--- a/fsck-cache.c
+++ b/fsck-cache.c
@@ -296,7 +296,7 @@ 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];
@@ -304,19 +304,23 @@ static void read_sha1_reference(const char *path)
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)