diff options
Diffstat (limited to 'meta-python/recipes-devtools/python/python3-checksec-py')
| -rw-r--r-- | meta-python/recipes-devtools/python/python3-checksec-py/0001-main-Add-option-to-ignore-symlinks.patch | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-checksec-py/0001-main-Add-option-to-ignore-symlinks.patch b/meta-python/recipes-devtools/python/python3-checksec-py/0001-main-Add-option-to-ignore-symlinks.patch new file mode 100644 index 0000000000..3a99ba33e3 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-checksec-py/0001-main-Add-option-to-ignore-symlinks.patch | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | From b540967b87394d855c26375ac5a9a7265f265053 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Maximilian Blenk <Maximilian.Blenk@bmw.de> | ||
| 3 | Date: Fri, 2 Jul 2021 14:42:25 +0200 | ||
| 4 | Subject: [PATCH] main: Add option to ignore symlinks | ||
| 5 | |||
| 6 | When analyzing a complete rootfs (which might not be the rootfs of the | ||
| 7 | analyzing system) symlinks within that rootfs might be broken. In | ||
| 8 | particular absolute symlinks. However, if by chance such a symlink | ||
| 9 | currently points to a valid binary in your system, this binary pointed | ||
| 10 | to is analyzed. This commit adds the possibility to ignore symlinks to | ||
| 11 | files (symlinks to dirs are already ignored by default). This allows to | ||
| 12 | solve the issue described above, and if the whole rootfs is analyzed | ||
| 13 | there shouldn't be a loss of information (because all the binaries will | ||
| 14 | be analyzed anyway). Additionally, this also saves some time when | ||
| 15 | performing the analysis. | ||
| 16 | |||
| 17 | Upstream-Status: Submitted [https://github.com/Wenzel/checksec.py/pull/106] | ||
| 18 | --- | ||
| 19 | checksec/__main__.py | 12 +++++++----- | ||
| 20 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
| 21 | |||
| 22 | diff --git a/checksec/__main__.py b/checksec/__main__.py | ||
| 23 | index a14862f..931d850 100644 | ||
| 24 | --- a/checksec/__main__.py | ||
| 25 | +++ b/checksec/__main__.py | ||
| 26 | @@ -8,6 +8,7 @@ Options: | ||
| 27 | -w WORKERS --workers=WORKERS Specify the number of process pool workers [default: 4] | ||
| 28 | -j --json Display results as JSON | ||
| 29 | -s LIBC --set-libc=LIBC Specify LIBC library to use to check for fortify scores (ELF) | ||
| 30 | + -i --ignore-symlinks Ignore symlinks to files | ||
| 31 | -d --debug Enable debug output | ||
| 32 | -h --help Display this message | ||
| 33 | """ | ||
| 34 | @@ -27,18 +28,18 @@ from .pe import PEChecksecData, PESecurity, is_pe | ||
| 35 | from .utils import lief_set_logging | ||
| 36 | |||
| 37 | |||
| 38 | -def walk_filepath_list(filepath_list: List[Path], recursive: bool = False) -> Iterator[Path]: | ||
| 39 | +def walk_filepath_list(filepath_list: List[Path], recursive: bool = False, ignore_symlinks: bool = False) -> Iterator[Path]: | ||
| 40 | for path in filepath_list: | ||
| 41 | if path.is_dir() and not path.is_symlink(): | ||
| 42 | try: | ||
| 43 | if recursive: | ||
| 44 | for f in os.scandir(path): | ||
| 45 | - yield from walk_filepath_list([Path(f)], recursive) | ||
| 46 | + yield from walk_filepath_list([Path(f)], recursive, ignore_symlinks) | ||
| 47 | else: | ||
| 48 | yield from (Path(f) for f in os.scandir(path)) | ||
| 49 | except OSError: | ||
| 50 | continue | ||
| 51 | - elif path.is_file(): | ||
| 52 | + elif path.is_file() and (not ignore_symlinks or not path.is_symlink()): | ||
| 53 | yield path | ||
| 54 | |||
| 55 | |||
| 56 | @@ -75,6 +76,7 @@ def main(args): | ||
| 57 | json = args["--json"] | ||
| 58 | recursive = args["--recursive"] | ||
| 59 | libc_path = args["--set-libc"] | ||
| 60 | + ignore_symlinks = args["--ignore-symlinks"] | ||
| 61 | |||
| 62 | # logging | ||
| 63 | formatter = "%(asctime)s %(levelname)s:%(name)s:%(message)s" | ||
| 64 | @@ -110,7 +112,7 @@ def main(args): | ||
| 65 | # we need to consume the iterator once to get the total | ||
| 66 | # for the progress bar | ||
| 67 | check_output.enumerating_tasks_start() | ||
| 68 | - count = sum(1 for i in walk_filepath_list(filepath_list, recursive)) | ||
| 69 | + count = sum(1 for i in walk_filepath_list(filepath_list, recursive, ignore_symlinks)) | ||
| 70 | check_output.enumerating_tasks_stop(count) | ||
| 71 | with ProcessPoolExecutor( | ||
| 72 | max_workers=workers, initializer=worker_initializer, initargs=(libc_path,) | ||
| 73 | @@ -119,7 +121,7 @@ def main(args): | ||
| 74 | check_output.processing_tasks_start() | ||
| 75 | future_to_checksec = { | ||
| 76 | pool.submit(checksec_file, filepath): filepath | ||
| 77 | - for filepath in walk_filepath_list(filepath_list, recursive) | ||
| 78 | + for filepath in walk_filepath_list(filepath_list, recursive, ignore_symlinks) | ||
| 79 | } | ||
| 80 | for future in as_completed(future_to_checksec): | ||
| 81 | filepath = future_to_checksec[future] | ||
