From 00515be4381676ba111648f6f268bb88e77f57eb Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Wed, 5 Mar 2025 19:46:35 +0100 Subject: [PATCH] Handle OSError exception Handle OSError which can be returned by os.scandir Signed-off-by: Fabrice Fontaine --- checksec/__main__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/checksec/__main__.py b/checksec/__main__.py index 856d0b3..a14862f 100644 --- a/checksec/__main__.py +++ b/checksec/__main__.py @@ -30,11 +30,14 @@ def walk_filepath_list(filepath_list: List[Path], recursive: 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) - else: - yield from (Path(f) for f in os.scandir(path)) + try: + if recursive: + for f in os.scandir(path): + yield from walk_filepath_list([Path(f)], recursive) + else: + yield from (Path(f) for f in os.scandir(path)) + except OSError: + continue elif path.is_file(): yield path