Menu

#55 Infinite loop caused by nested symlinks

None
closed-fixed
nobody
None
5
2018-03-14
2018-01-27
reikred
No

I found that certain structures of nested symlinks cause rhash to go into what appears to be an endless/infinite loop. Here is a simplified test case that I generated;

mkdir -p /tmp/xxx/a/b/c
cd /tmp/xxx/a/b/c/
ln -s ../../b d
ln -s ../.././a e
cp -p /etc/hosts x
#cd  /tmp/xxx # optional, will get an endless loop either way
rhash -r --md5 . | more
# at this point it looks like I have an infinite loop

d442aaf70605eacbfe61df73d812a461 x
d442aaf70605eacbfe61df73d812a461 d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/x
d442aaf70605eacbfe61df73d812a461 d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/d/c/x
...
...

One way to break the infinite loop would be to have an command line option not to follow symlinks, and maybe also not to follow hardlinks if the link is to a directory?

Or you could use a similar covention as the tools hashdeep and md5deep. They have an option that allows the user to select what kinds of files will be processed:

-o <bcpflsd>
Enables expert mode. Allows the user specify which (and only which) types of files are processed. Directory processing is still controlled
with the -r flag. The expert mode options allowed are:
f - Regular files
b - Block Devices
c - Character Devices
p - Named Pipes
l - Symbolic Links
s - Sockets
d - Solaris Doors
e - Windows PE executables</bcpflsd>

I know -o is used for something else in rhash already, just an idea to keep things similar if you think that is desirable. Maybe ---filetypes <bcpflsd> or some such.</bcpflsd>

Discussion

  • Aleksey

    Aleksey - 2018-02-18

    This was caused by bug with symlinks handling. It should be fixed by https://github.com/rhash/RHash/commit/67922161f3a71a4e4d7fc0892b14c4899b293f6e

    Now to follow symlinks, while scanning directories recursively, use the --follow option.

     
  • reikred

    reikred - 2018-02-24

    Thank you very much, Aleksey it works great now with the fix.

     

    Last edit: reikred 2018-02-24
  • Aleksey

    Aleksey - 2018-03-14

    The fix is included into ** RHash v1.3.6**.

     
  • Aleksey

    Aleksey - 2018-03-14
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB