Browse Source

closes gh-2395: safe conversion of `SYSLOG_PID` or `_PID` (if journal entry contains a string instead of numeric)

pull/2369/merge
Sergey G. Brester 6 years ago committed by GitHub
parent
commit
7a463eb3f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      fail2ban/server/filtersystemd.py

9
fail2ban/server/filtersystemd.py

@ -204,7 +204,14 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
if not v:
v = logentry.get('_PID')
if v:
logelements[-1] += ("[%i]" % v)
try: # [integer] (if already numeric):
v = "[%i]" % v
except TypeError:
try: # as [integer] (try to convert to int):
v = "[%i]" % int(v, 0)
except (TypeError, ValueError): # fallback - [string] as it is
v = "[%s]" % v
logelements[-1] += v
logelements[-1] += ":"
if logelements[-1] == "kernel:":
if '_SOURCE_MONOTONIC_TIMESTAMP' in logentry:

Loading…
Cancel
Save