[gvfs/gnome-2-28] Reread metadata only when the inodes are different



commit 6e397fbf15e074ba598de33240596f6b31211dc5
Author: Christian Kellner <gicmo gnome org>
Date:   Wed Nov 18 14:40:38 2009 +0100

    Reread metadata only when the inodes are different
    
    This will protect against bugs where the stable file has the rotated bug set (which should never happen but see bug #600057)
    (cherry picked from commit 5e0cd74ada6749ab7e489db2fa22bd8cb5d2881c)

 metadata/metatree.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/metadata/metatree.c b/metadata/metatree.c
index 36abb9b..4a0e5f5 100644
--- a/metadata/metatree.c
+++ b/metadata/metatree.c
@@ -158,6 +158,7 @@ struct _MetaTree {
   int fd;
   char *data;
   gsize len;
+  ino_t inode;
 
   guint32 tag;
   gint64 time_t_base;
@@ -469,6 +470,7 @@ meta_tree_init (MetaTree *tree)
 
   tree->fd = fd;
   tree->len = statbuf.st_size;
+  tree->inode = statbuf.st_ino;
   tree->data = data;
   tree->header = (MetaFileHeader *)data;
 
@@ -614,12 +616,24 @@ meta_tree_unref (MetaTree *tree)
 static gboolean
 meta_tree_needs_rereading (MetaTree *tree)
 {
+  struct stat statbuf;
+
   if (tree->fd == -1)
     return TRUE;
 
   if (tree->header != NULL &&
       GUINT32_FROM_BE (tree->header->rotated) == 0)
     return FALSE; /* Got a valid tree and its not rotated */
+
+  /* Sanity check to avoid infinite loops when a stable file
+     has the rotated bit set to 1 (see gnome bugzilla bug #600057) */
+
+  if (lstat (tree->filename, &statbuf) != 0)
+    return FALSE;
+
+  if (tree->inode == statbuf.st_ino)
+    return FALSE;
+
   return TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]