From: Kamil Dudka Date: Wed, 11 Feb 2015 17:41:43 +0000 (+0100) Subject: fts: avoid crash when a cycle is added while traversing X-Git-Tag: accepted/tizen/5.5/base/20191030.081539^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ead692bcf0e3aacd3eb9ff0a14811a9122c5c57;p=product%2Fupstream%2Ffindutils.git 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. Change-Id: I24bfd7a2f46197ec8dff5ddabca3cab3837b28be Signed-off-by: Hyunjee Kim --- diff --git a/gnulib/lib/fts.c b/gnulib/lib/fts.c index 1b5384b..501b334 100644 --- a/gnulib/lib/fts.c +++ b/gnulib/lib/fts.c @@ -809,9 +809,16 @@ check_for_dir: 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; }