Fix canonicalize loop-detection corner case.
authorJim Meyering <jim@meyering.net>
Fri, 28 Sep 2007 21:26:49 +0000 (23:26 +0200)
committerJim Meyering <jim@meyering.net>
Fri, 28 Sep 2007 21:28:18 +0000 (23:28 +0200)
Do not attempt to stat the symlink values stored via seen_triple.
Without this, coreutils' tests/misc/readlink-fp-loop test would fail
on linux-2.6.18, (but not 2.6.22).
* lib/canonicalize.c (seen_triple): Use triple_compare_ino_str, not
triple_compare.  The former compares dev,ino,filename, while the latter
would actually stat dirname(filename) when dev and ino were equal.
* lib/hash-triple.c: Install <string.h>.
(STREQ): Define.
(triple_compare_ino_str): New function.
* lib/hash-triple.h (triple_compare_ino_str): Declare it.

ChangeLog
lib/canonicalize.c
lib/hash-triple.c
lib/hash-triple.h

index 80a7159338bcca2415ef018199fffb504de6ad68..44972ece2180107a48976180de6888e0f09cc25d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-09-28  Jim Meyering  <jim@meyering.net>
+
+       Fix canonicalize loop-detection corner case.
+       Do not attempt to stat the symlink values stored via seen_triple.
+       Without this, coreutils' tests/misc/readlink-fp-loop test would fail
+       on linux-2.6.18, (but not 2.6.22).
+       * lib/canonicalize.c (seen_triple): Use triple_compare_ino_str, not
+       triple_compare.  The former compares dev,ino,filename, while the latter
+       would actually stat dirname(filename) when dev and ino were equal.
+       * lib/hash-triple.c: Install <string.h>.
+       (STREQ): Define.
+       (triple_compare_ino_str): New function.
+       * lib/hash-triple.h (triple_compare_ino_str): Declare it.
+
 2007-09-28  Eric Blake  <ebb9@byu.net>
 
        Enforce that AC_REPLACE_FUNCS files exist.
index af2703cf7aa4c9ed7ad7b1c2ad628545a95aa72a..bbf3855f2ffb8fb463f87b3605768ebd42cca9a5 100644 (file)
@@ -135,7 +135,7 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st)
       *ht = hash_initialize (initial_capacity,
                            NULL,
                            triple_hash,
-                           triple_compare,
+                           triple_compare_ino_str,
                            triple_free);
       if (*ht == NULL)
        xalloc_die ();
index 2644b5f677b05b109ac75f295d3911593b0b762f..a65a4db9be54eca3d68e6385d0e01dcea41d66bf 100644 (file)
 #include "hash-triple.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "hash-pjw.h"
 #include "same.h"
 #include "same-inode.h"
 
+#define STREQ(a, b) (strcmp ((a), (b)) == 0)
+
 /* Hash an F_triple, and *do* consider the file name.  */
 size_t
 triple_hash (void const *x, size_t table_size)
@@ -57,6 +60,14 @@ triple_compare (void const *x, void const *y)
   return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
 }
 
+bool
+triple_compare_ino_str (void const *x, void const *y)
+{
+  struct F_triple const *a = x;
+  struct F_triple const *b = y;
+  return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
+}
+
 /* Free an F_triple.  */
 void
 triple_free (void *x)
index 7abe9704413988d7d1c1b28f35b508a25d51a173..51863c9dffc6f3bf7599e1b77155b1a26ab9de43 100644 (file)
@@ -16,6 +16,7 @@ struct F_triple
 extern size_t triple_hash (void const *x, size_t table_size);
 extern size_t triple_hash_no_name (void const *x, size_t table_size);
 extern bool triple_compare (void const *x, void const *y);
+extern bool triple_compare_ino_str (void const *x, void const *y);
 extern void triple_free (void *x);
 
 #endif