Skip to content

Commit

Permalink
Test ClamAV db before importing
Browse files Browse the repository at this point in the history
  • Loading branch information
kam193 committed Feb 25, 2024
1 parent 27204a5 commit 1e3cec2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clamav-service/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55
56
15 changes: 15 additions & 0 deletions clamav-service/service/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,25 @@ def do_source_update(self, service: Service) -> None:
super().do_source_update(service)
self._clean_up_old_sources(service, self.latest_updates_dir)

def _test_database_file(self, file: str) -> bool:
result = subprocess.run(
["clamscan", "-d", file, "README.md"], capture_output=True, text=True
)

if result.returncode != 2:
return

self.log.warning(
"Database file %s is not a valid ClamAV database file, reason: %s", file, result.stderr
)

raise ValueError(result.stderr)

def import_update(self, files_sha256, source, default_classification=None) -> None:
output_dir = os.path.join(self.latest_updates_dir, source)
os.makedirs(os.path.join(self.latest_updates_dir, source), exist_ok=True)
for file, _ in files_sha256:
self._test_database_file(file)
self.log.debug("Copying %s to %s", file, output_dir)
shutil.copy(file, output_dir)

Expand Down

0 comments on commit 1e3cec2

Please sign in to comment.