diff options
author | Rob Landley <rob@landley.net> | 2014-12-01 12:52:55 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-12-01 12:52:55 -0600 |
commit | 10e0d86c088a3eccc27095b51d753e05f3f3cbc8 (patch) | |
tree | c7c2658c41dc0049ceb09b687338c238b21e2791 /toys/posix | |
parent | ef6a773198040a05a56dec2261516fb149823cf6 (diff) | |
download | toybox-10e0d86c088a3eccc27095b51d753e05f3f3cbc8.tar.gz |
Ashwini Sharma pointed out that "mkdir sub; ln -s . sub/up; du -L sub" shouldn't loop endlessly.
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/du.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/toys/posix/du.c b/toys/posix/du.c index 22a26d3a..00a7f68a 100644 --- a/toys/posix/du.c +++ b/toys/posix/du.c @@ -110,6 +110,15 @@ static int do_du(struct dirtree *node) if ((toys.optflags & FLAG_x) && (TT.st_dev != node->st.st_dev)) return 0; + // Don't loop endlessly on recursive directory symlink + if (toys.optflags & FLAG_L) { + struct dirtree *try = node; + + while ((try = try->parent)) + if (node->st.st_dev==try->st.st_dev && node->st.st_ino==try->st.st_ino) + return 0; + } + // Don't count hard links twice if (!(toys.optflags & FLAG_l) && !node->again) if (seen_inode(&TT.inodes, &node->st)) return 0; |