findutils/findutils-4.5.14-fts-cycle.patch

45 lines
1.5 KiB
Diff

From bf4d8abd7ae3624a13967275dcbaea19f6b6ceb5 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 11 Feb 2015 13:48:12 +0100
Subject: [PATCH] fts: avoid crash when a cycle is added while traversing
This could be triggered by auto-mounting a recursive bind mount.
Reported by Michael Chapman in: https://bugzilla.redhat.com/1188498
* lib/fts.c (fts_read): Avoid removing the original hash table item
when leaving a directory that caused a cycle, and preserve the FTS_DC
flag.
Bug: https://bugzilla.redhat.com/1188498
Bug: http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/34867
---
gl/lib/fts.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/gl/lib/fts.c b/gl/lib/fts.c
index 500e92c..f76c015 100644
--- a/gl/lib/fts.c
+++ b/gl/lib/fts.c
@@ -1091,9 +1091,16 @@ cd_dot_dot:
p->fts_errno = errno;
SET(FTS_STOP);
}
- p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
- if (p->fts_errno == 0)
- LEAVE_DIR (sp, p, "3");
+
+ /* If the directory causes a cycle, preserve the FTS_DC flag and keep
+ * the corresponding dev/ino pair in the hash table. It is going to be
+ * removed when leaving the original directory.
+ */
+ if (p->fts_info != FTS_DC) {
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ if (p->fts_errno == 0)
+ LEAVE_DIR (sp, p, "3");
+ }
return ISSET(FTS_STOP) ? NULL : p;
}
--
2.1.0