Skip to content

Commit

Permalink
Fix systemd get_version() (#1156)
Browse files Browse the repository at this point in the history
Fixes: #1155
  • Loading branch information
BreadGenie committed May 13, 2021
1 parent 68b177f commit 36991da
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions cve_bin_tool/checkers/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
https://www.cvedetails.com/product/38088/Freedesktop-Systemd.html?vendor_id=7971
"""

from cve_bin_tool.checkers import Checker

from ..util import regex_find


class SystemdChecker(Checker):
CONTAINS_PATTERNS = [
Expand All @@ -28,9 +31,36 @@ class SystemdChecker(Checker):
]
VENDOR_PRODUCT = [("freedesktop", "systemd")]

"""
Using filenames (containing patterns like '.so' etc.) in the binaries as VERSION_PATTERNS aren't ideal.
The reason behind this is that these might depend on who packages the file (like it
might work on fedora but not on ubuntu)
"""

"""
Using filenames (containing patterns like '.so' etc.) in the binaries as VERSION_PATTERNS aren't ideal.
The reason behind this is that these might depend on who packages the file (like it
might work on fedora but not on ubuntu)
"""
def get_version(self, lines, filename):
def guess_contains_systemd(lines):
"""Tries to determine if a file includes systemd"""
for line in lines:
if "sd_bus_error_copy" in line:
return 1
if "sd_bus_error_is_set" in line:
return 1
if "sd_bus_error_add_map" in line:
return 1
return 0

version_info = {}

if "libsystemd.so." in filename:
version_info["is_or_contains"] = "is"

elif guess_contains_systemd(lines):
version_info["is_or_contains"] = "contains"

if "is_or_contains" in version_info:
version_info["modulename"] = "systemd"
version_info["version"] = regex_find(
sorted(lines, reverse=True), self.VERSION_PATTERNS
)

return version_info

0 comments on commit 36991da

Please sign in to comment.