Add option to ignore symlinks completely#106
Open
blenk92 wants to merge 1 commit intoWenzel:masterfrom
Open
Conversation
16583e3 to
8748187
Compare
Wenzel
requested changes
Jul 27, 2021
checksec/__main__.py
Outdated
| yield from walk_filepath_list([Path(f)], recursive) | ||
| yield from walk_filepath_list([Path(f)], recursive, ignore_symlinks) | ||
| else: | ||
| yield from (Path(f) for f in os.scandir(path)) |
Owner
There was a problem hiding this comment.
The issue is that this line will yield any path, and not filter on the symlink as expected.
for example, if you have some symlinks in /usr/lib (/usr/lib/cpp -> /etc/alternatives/cpp),
running checksec.py -i /usr/lib will still yield /usr/lib/cpp because it goes through that yield from
Can you find a way to rework that function ?
Owner
There was a problem hiding this comment.
This is a fix, I duplicated the condition:
def walk_filepath_list(filepath_list: List[Path], recursive: bool = False, ignore_symlinks: bool = False) -> Iterator[Path]:
for path in filepath_list:
if path.is_dir() and not path.is_symlink():
if recursive:
for f in os.scandir(path):
yield from walk_filepath_list([Path(f)], recursive, ignore_symlinks)
else:
yield from (Path(f) for f in os.scandir(path) if f.is_file()
and (not ignore_symlinks or not f.is_symlink()))
elif path.is_file() and (not ignore_symlinks or not path.is_symlink()):
yield pathbut i don't like duplication 😕
Contributor
Author
There was a problem hiding this comment.
Hi, sure i can try to come up with something ;-)
Contributor
Author
There was a problem hiding this comment.
hope switching to os.walk() is fine for you, seemed a bit simpler to me ;-)
3e544f8 to
0be298b
Compare
When analyzing a complete rootfs (which might not be the rootfs of the analyzing system) symlink within that rootfs might be broken. In particular absolute symlinks. However, if by chance such a symlink currently points to a valid binary in your system, this binary pointed to is analyzed. This commit adds the possibility to ignore symlinks to files (symlinks to dirs are already ignored by default). This allows to solve the issue described above, and if the whole rootfs is analyzed there shouldn't be a loss of information (because all the binaries will be analyzed anyway). Additionally, this also saves some time when performing the analysis. This commit also involves some refactoring of the walk_filepath_list() function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When analyzing a complete rootfs (which might not be the rootfs of the
analyzing system) symlink within that rootfs might be broken. In
particular absolute symlinks. However, if by chance such a symlink
currently points to a valid binary in your system, this binary pointed
to is analyzed. This commit adds the possibility to ignore symlinks to
files (symlinks to dirs are already ignored by default). This allows to
solve the issue described above, and if the whole rootfs is analyzed
there shouldn't be a loss of information (because all the binaries will
be analyzed anyway). Additionally, this also saves some time when
performing the analysis.