Blob Blame History Raw
From 5e0cd74ada6749ab7e489db2fa22bd8cb5d2881c Mon Sep 17 00:00:00 2001
From: Christian Kellner <gicmo@gnome.org>
Date: Wed, 18 Nov 2009 13:40:38 +0000
Subject: 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)
---
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;
 }
 
--
cgit v0.8.2