]> git.wh0rd.org Git - fontconfig.git/commitdiff
Make fccache more resilient to broken cache files by checking return value
authorPatrick Lam <plam@MIT.EDU>
Mon, 30 Jan 2006 15:44:13 +0000 (15:44 +0000)
committerPatrick Lam <plam@MIT.EDU>
Mon, 30 Jan 2006 15:44:13 +0000 (15:44 +0000)
    of FcCacheReadString all the time.
reviewed by: plam

ChangeLog
src/fccache.c

index c94e800087a754ab998240fd1adec1cc47ed7955..4755e7fb4e16fbd4a5dde709960449ff275212ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-01-30  Mike Fabian  <mfabian@suse.de>
+       reviewed by: plam
+
+       * src/fccache.c (FcGlobalCacheLoad, FcDirCacheUnlink
+                        FcDirCacheOpen, FcDirCacheRead, FcDirCacheWrite):
+
+       Make fccache more resilient to broken cache files by checking
+       return value of FcCacheReadString all the time.
+
 2006-01-30  Frederic Crozat  <fcrozat@mandriva.com>
        reviewed by: plam
 
index 853ae0e1d00bef2769867628a150868722ee898c..5af247a13ff23b9ce9e9185f4b45dfebdff81fd9 100644 (file)
@@ -218,7 +218,8 @@ FcGlobalCacheLoad (FcGlobalCache    *cache,
 
     cache->updated = FcFalse;
 
-    FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));
+    if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)))
+       return;
     if (strcmp (name_buf, FC_GLOBAL_MAGIC_COOKIE) != 0)
        return;
 
@@ -229,8 +230,9 @@ FcGlobalCacheLoad (FcGlobalCache    *cache,
         goto bail_and_destroy;
 
     lseek (cache->fd, current_arch_start, SEEK_SET);
-    FcCacheReadString (cache->fd, candidate_arch_machine_name, 
-                       sizeof (candidate_arch_machine_name));
+    if (!FcCacheReadString (cache->fd, candidate_arch_machine_name, 
+                           sizeof (candidate_arch_machine_name)))
+       goto bail_and_destroy;
     if (strlen(candidate_arch_machine_name) == 0)
        goto bail_and_destroy;
 
@@ -238,8 +240,7 @@ FcGlobalCacheLoad (FcGlobalCache    *cache,
     {
        off_t targ;
 
-       FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));
-       if (!strlen(name_buf))
+       if (!FcCacheReadString (cache->fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
            break;
 
        /* Directory must be older than the global cache file; also
@@ -721,8 +722,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
            return FcTrue;
        }
 
-       FcCacheReadString (fd, name_buf, sizeof (name_buf));
-       if (!strlen(name_buf))
+       if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
        {
            FcStrFree ((FcChar8 *)cache_hashed);
            goto bail;
@@ -943,8 +943,7 @@ FcDirCacheOpen (const FcChar8 *dir)
            FcStrFree ((FcChar8 *)cache_file);
            return -1;
        }
-       FcCacheReadString (fd, name_buf, sizeof (name_buf));
-       if (!strlen(name_buf))
+       if (!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
            goto bail;
 
        name_buf_dir = FcStrDirname ((FcChar8 *)name_buf);
@@ -990,7 +989,7 @@ FcDirCacheRead (FcFontSet * set, FcStrSet * dirs, const FcChar8 *dir, FcConfig *
                           sizeof (candidate_arch_machine_name)) == 0)
        goto bail1;
 
-    while (strlen(FcCacheReadString (fd, subdirName, sizeof (subdirName))) > 0)
+    while (FcCacheReadString (fd, subdirName, sizeof (subdirName)) && strlen (subdirName) > 0)
         FcStrSetAdd (dirs, (FcChar8 *)subdirName);
 
     if (!FcDirCacheConsume (fd, (const char *)dir, set, config))
@@ -1130,11 +1129,12 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir)
        fd = open(cache_hashed, O_RDONLY);
        if (fd == -1)
            break;
-       FcCacheReadString (fd, name_buf, sizeof (name_buf));
-       close (fd);
-
-       if (!strlen(name_buf))
+       if(!FcCacheReadString (fd, name_buf, sizeof (name_buf)) || !strlen(name_buf))
+       {
+           close (fd);
            break;
+       }
+       close (fd);
 
        if (strcmp (name_buf, cache_file) != 0)
            continue;