Skip to content

Commit

Permalink
Replace BaseException with Exception
Browse files Browse the repository at this point in the history
BaseException includes exceptions like SystemExit, KeyboardInterrupt
and GeneratorExit that we should not be catching.
  • Loading branch information
brianmay committed Apr 24, 2022
1 parent 9e3209e commit d6fa0c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions sshuttle/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def main(method_name, syslog):
break
try:
(family, width, exclude, ip, fport, lport) = \
line.strip().split(',', 5)
except BaseException:
line.strip().split(',', 5)
except Exception:
raise Fatal('expected route or NSLIST but got %r' % line)
subnets.append((
int(family),
Expand All @@ -222,7 +222,7 @@ def main(method_name, syslog):
break
try:
(family, ip) = line.strip().split(',', 1)
except BaseException:
except Exception:
raise Fatal('expected nslist or PORTS but got %r' % line)
nslist.append((int(family), ip))
debug2('Got partial nslist: %r' % nslist)
Expand Down Expand Up @@ -317,46 +317,46 @@ def main(method_name, syslog):
finally:
try:
debug1('undoing changes.')
except BaseException:
except Exception:
debug2('An error occurred, ignoring it.')

try:
if subnets_v6 or nslist_v6:
debug2('undoing IPv6 changes.')
method.restore_firewall(port_v6, socket.AF_INET6, udp, user)
except BaseException:
except Exception:
try:
debug1("Error trying to undo IPv6 firewall.")
debug1(traceback.format_exc())
except BaseException:
except Exception:
debug2('An error occurred, ignoring it.')

try:
if subnets_v4 or nslist_v4:
debug2('undoing IPv4 changes.')
method.restore_firewall(port_v4, socket.AF_INET, udp, user)
except BaseException:
except Exception:
try:
debug1("Error trying to undo IPv4 firewall.")
debug1(traceback.format_exc())
except BaseException:
except Exception:
debug2('An error occurred, ignoring it.')

try:
# debug2() message printed in restore_etc_hosts() function.
restore_etc_hosts(hostmap, port_v6 or port_v4)
except BaseException:
except Exception:
try:
debug1("Error trying to undo /etc/hosts changes.")
debug1(traceback.format_exc())
except BaseException:
except Exception:
debug2('An error occurred, ignoring it.')

try:
flush_systemd_dns_cache()
except BaseException:
except Exception:
try:
debug1("Error trying to flush systemd dns cache.")
debug1(traceback.format_exc())
except BaseException:
except Exception:
debug2("An error occurred, ignoring it.")
2 changes: 1 addition & 1 deletion sshuttle/hostwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def write_host_cache():

try:
os.unlink(tmpname)
except BaseException:
except Exception:
pass


Expand Down

0 comments on commit d6fa0c1

Please sign in to comment.