Improve error reporting when find malformed comment in user.rules
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ufw |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
ufw 0.35 (xenial) but issue appears to be in HEAD also.
When running against a config with a corrupted comment line in /etc/ufw/
# ufw status
Traceback (most recent call last):
File "/usr/sbin/ufw", line 137, in <module>
res = ui.do_action(
File "/usr/lib/
res = self.get_status()
File "/usr/lib/
out = self.backend.
File "/usr/lib/
comment_str = " # %s" % r.get_comment()
File "/usr/lib/
return ufw.util.
File "/usr/lib/
return binascii.
binascii.Error: Non-hexadecimal digit found
In my case, this was because someone had hand-edited the user.rules file and mangled the comment field.
Since ufw was otherwise functional, it would be better to handle this error gracefully. The simplest method might be to return an error in the displayed comment rather than throwing a fatal exception.
PATCH FOLLOWS
-------------
*** /usr/lib/
--- /usr/lib/
*************** def hex_decode(h):
*** 1063,1066 ****
'''Take a hex string and convert it to a string'''
if sys.version_info[0] < 3:
return h.decode(
! return binascii.
--- 1063,1069 ----
'''Take a hex string and convert it to a string'''
if sys.version_info[0] < 3:
return h.decode(
! try:
! return binascii.
! except:
! return '<Bad string>'
Changed in ufw: | |
status: | New → Triaged |
importance: | Undecided → Wishlist |
importance: | Wishlist → Low |
summary: |
- crashes on corrupt comments in config [PATCH] + crash with malformed user.rules |
s/user. conf/user. rules/g