Skip to content

Commit 3fd9bd4

Browse files
committed
dict_gen: Handle case of error opening man file
There may be cases when there is a missing symlink or a man page file is not accessible. Handle exception of opening that file: do nothing, return from the generator function. Signed-off-by: Razvan Deaconescu <[email protected]>
1 parent 57e723f commit 3fd9bd4

File tree

1 file changed

+13
-9
lines changed
  • attack_surface_approximation/dictionaries_generators/heuristics

1 file changed

+13
-9
lines changed

attack_surface_approximation/dictionaries_generators/heuristics/man_parsing.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ def __get_arguments_from_manual(
2121
filter_func: typing.Callable,
2222
unescape: typing.Callable = None,
2323
) -> typing.Generator[str, None, None]:
24-
with gzip.open(filename, "rt") as manual:
25-
try:
26-
content = manual.read()
27-
except UnicodeDecodeError:
28-
return
24+
try:
25+
manual = gzip.open(filename, "rt")
26+
except:
27+
return
2928

30-
if unescape:
31-
content = unescape(content)
29+
try:
30+
content = manual.read()
31+
except UnicodeDecodeError:
32+
return
3233

33-
arguments = filter_func(content)
34-
yield from arguments
34+
if unescape:
35+
content = unescape(content)
36+
37+
arguments = filter_func(content)
38+
yield from arguments
3539

3640

3741
def generate(_: str = None) -> typing.List[str]:

0 commit comments

Comments
 (0)