Prevent CodeQL from losing its mind. Properly checking for instances of the interface

This commit is contained in:
Andrew Case
2025-03-14 20:43:12 +00:00
parent cf8bb3dfbc
commit 2e93b8ed09
@@ -225,23 +225,6 @@ class Modules(interfaces.configuration.VersionableInterface):
return ModuleInfo(module.vol.offset, mod_name, start, end)
@classmethod
def _validate_gatherers(cls, caller_wanted_gatherers) -> List[str]:
"""
Called by `run_modules_scanners` to validate the caller supplied gatherers list
An exception is thrown if an empty gatherers list is given or a list containing an invalid source
"""
if not caller_wanted_gatherers:
raise ValueError(
"`caller_wanted_gatherers` must have at least one gatherer."
)
for gatherer in caller_wanted_gatherers:
if gatherer not in ModuleGatherers.all_gatherers_identifier:
raise ValueError(
f"Invalid gatherer sent through `caller_wanted_gatherers`: {gatherer}"
)
@classmethod
def run_modules_scanners(
cls,
@@ -268,8 +251,20 @@ class Modules(interfaces.configuration.VersionableInterface):
Returns:
Dictionary mapping each plugin to its corresponding result
"""
# Throws ValueError if invalid gatherers sent in
Modules._validate_gatherers(caller_wanted_gatherers)
if not caller_wanted_gatherers:
raise ValueError(
"`caller_wanted_gatherers` must have at least one gatherer."
)
if not isinstance(caller_wanted_gatherers, Iterable):
raise ValueError("`caller_wanted_gatherers` must be iterable")
for gatherer in caller_wanted_gatherers:
if not issubclass(gatherer, ModuleGathererInterface):
raise ValueError(
f"Invalid gatherer sent through `caller_wanted_gatherers`: {gatherer}"
)
kernel = context.modules[kernel_module_name]