Skip to content

Commit

Permalink
cwe-checker: add memory limit (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke authored Oct 30, 2023
1 parent e0dc06d commit 740e9c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/config/fact-core-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ processes = 4
name = "cve_lookup"
processes = 4

[[backend.plugin]]
name = "cwe_checker"
processes = 2
memory-limit = "4G"
# see https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details
# unintuitively, if memswap-limit is set to the same value as memory-limit, the swap will *not* be used
memswap-limit = "4G"

[[backend.plugin]]
name = "elf_analysis"
processes = 4
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/analysis/cwe_checker/code/cwe_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from docker.types import Mount

import config
from analysis.PluginBase import AnalysisBasePlugin
from helperFunctions.docker import run_docker_container

Expand All @@ -36,7 +37,7 @@ class AnalysisPlugin(AnalysisBasePlugin):
'Due to the nature of static analysis, this plugin may run for a long time.'
)
DEPENDENCIES = ['cpu_architecture', 'file_type'] # noqa: RUF012
VERSION = '0.5.2'
VERSION = '0.5.3'
TIMEOUT = 600 # 10 minutes
MIME_WHITELIST = [ # noqa: RUF012
'application/x-executable',
Expand All @@ -50,6 +51,8 @@ class AnalysisPlugin(AnalysisBasePlugin):

def additional_setup(self):
self._log_version_string()
self.memory_limit = getattr(config.backend.plugin.get(self.NAME, None), 'memory_limit', '4G')
self.swap_limit = getattr(config.backend.plugin.get(self.NAME, None), 'memswap_limit', '4G')

def _log_version_string(self):
output = self._run_cwe_checker_to_get_version_string()
Expand Down Expand Up @@ -78,6 +81,8 @@ def _run_cwe_checker_in_docker(self, file_object):
mounts=[
Mount('/input', file_object.file_path, type='bind'),
],
mem_limit=self.memory_limit,
memswap_limit=self.swap_limit,
)
return result.stdout

Expand Down

0 comments on commit 740e9c2

Please sign in to comment.