Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yara -r trapped in endless loop on symlink to current directory #2021

Closed
ruppde opened this issue Dec 4, 2023 · 0 comments
Closed

yara -r trapped in endless loop on symlink to current directory #2021

ruppde opened this issue Dec 4, 2023 · 0 comments
Labels

Comments

@ruppde
Copy link
Contributor

ruppde commented Dec 4, 2023

Describe the bug
If yara -r runs into a symlink to .. it's trapped in a endless loop. A common example of this is the Debian package of llvm which creates in /lib/llvm-11/build/ the following symlink:

lrwxrwxrwx 1 root root    2 Jan 27  2022 Debug+Asserts -> ../

To Reproduce

$ mkdir -p /tmp/d1/d2
$ cd /tmp/d1/d2
$ ln -s .. d3
$ ln -s .. d4
$ echo "rule test { condition: filesize > 1MB }" > test.yar
$ $ yara -rn test.yar .
test ./test.yar
test ./d4/d2/test.yar
test ./d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4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/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
test ./d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/d4/d2/test.yar
...

Expected behavior
Don't follow symlinks to ..

Please complete the following information:

  • OS: Linux
  • YARA version: 4.3.2

Additional context
This fixes to problem but there are probably more elegant solutions (I'm not a C coder ;)
image

@ruppde ruppde added the bug label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant