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

ClamDScan: --fdpass/--stream leak; ExcludePath issues (for 0.103.4) #203

Conversation

micahsnyder
Copy link
Contributor

This is just a backport of f7c9f6f?file-filters%5B%5D= (minus the python-based test) for 0.103.4

ClamDScan will leak the memory for the scan target filename if using
`--fdpass` or using `--stream`. This commit fixes that leak.
Resolves: https://bugzilla.clamav.net/show_bug.cgi?id=12648

ClamDScan will fail to scan any file after running into an
"ExcludePath" exclusion when using `--fdpass` or `--stream` AND
--multiscan (-m). The issue is because the parallel_callback()
callback function used by file tree walk (ftw) feature returns an
error code for excluded files rather than "success".
Memory for the accidentally-excluded paths for a given directory also
appears to be leaked.
This commit resolves this accidental-abort issue and the memory leak.

There was an additional single file path memory leak when using
`--fdpass` caused by bad error handling in `cli_ftw()`.
This was fixed by removing the confusing ternaries, and using
separate pointers for each filename copy.

ClamDScan with ExcludePath regex may fail to exclude absolute paths
when performing relative scans because the exclude-check function may
match using provided relative path (E.g. `/some/path/../another/path`)
rather than an absolute path (E.g. `/some/path/another/path`).
This issue is resolved by getting the real path at the start of the
scan, eliminating `.` and `..` relative pathing from all filepaths.

TODO 1: In addition to being recursive (bad for stack safety), the
File Tree Walk (FTW) implementation is a spaghetti code and should
be refactored.

TODO 2: ExcludePath will print out "Excluded" for each path that is
excluded when using `--fdpass` or `--stream`, and for each path
directly scanned that is directly excluded. But in a recursive
regular-scan, the "Excluded" message for the those paths is missing.
@micahsnyder micahsnyder changed the title ClamDScan: --fdpass/--stream leak; ExcludePath issues ClamDScan: --fdpass/--stream leak; ExcludePath issues (for 0.103.4) Jul 18, 2021
@micahsnyder micahsnyder added this to the 0.103.4 milestone Jul 19, 2021
@micahsnyder micahsnyder merged commit 6b8cc5d into Cisco-Talos:dev/0.103.4 Aug 3, 2021
@micahsnyder micahsnyder deleted the CLAM-1404-CLAM-1508-clamdscan-leaks-excludepath-abort-0.103.4 branch August 3, 2021 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant