Fix segfault (reported by fcrozat) caused by incorrect input on cache

files.
This commit is contained in:
Patrick Lam 2006-02-18 17:56:25 +00:00
parent 310817371c
commit a68ce9525d
2 changed files with 19 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2006-02-18 Patrick Lam <plam@mit.edu>
* src/fccache.c (FcDirCacheHasCurrentArch):
Fix segfault (reported by fcrozat) caused by incorrect
input on cache files.
2006-02-17 Patrick Lam <plam@mit.edu> 2006-02-17 Patrick Lam <plam@mit.edu>
* src/fcint.h (FC_CACHE_MAGIC): * src/fcint.h (FC_CACHE_MAGIC):

View File

@ -760,6 +760,7 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
off_t current_arch_start; off_t current_arch_start;
char *current_arch_machine_name; char *current_arch_machine_name;
FcCache metadata; FcCache metadata;
char subdirName[FC_MAX_FILE_LEN + 1 + 12 + 1];
fd = FcDirCacheOpen (dir); fd = FcDirCacheOpen (dir);
if (fd < 0) if (fd < 0)
@ -770,17 +771,19 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
if (current_arch_start >= 0) if (current_arch_start >= 0)
{ {
if (lseek (fd, current_arch_start, SEEK_SET) != current_arch_start)
goto bail1;
FcCacheSkipString (fd);
while (FcCacheReadString (fd, subdirName, sizeof (subdirName)) && strlen (subdirName) > 0)
;
if (read(fd, &metadata, sizeof(FcCache)) != sizeof(FcCache)) if (read(fd, &metadata, sizeof(FcCache)) != sizeof(FcCache))
{ goto bail1;
close (fd);
return FcFalse;
}
if (metadata.magic != FC_CACHE_MAGIC) if (metadata.magic != FC_CACHE_MAGIC)
{ goto bail1;
close (fd);
return FcFalse;
}
} }
close (fd); close (fd);
@ -790,6 +793,8 @@ FcDirCacheHasCurrentArch (const FcChar8 *dir)
return FcTrue; return FcTrue;
bail1:
close (fd);
bail: bail:
return FcFalse; return FcFalse;
} }