Skip to content

Commit

Permalink
Fix: Stop and clean finished/running openvas process before resumming…
Browse files Browse the repository at this point in the history
… a scan

If Ospd-Openvas crashes during a scan, probably the scan will continue
running in background, leaving the kb in redis occupied.
After ospd-openvas is initialized, the task can be resumed.
In this case, the scan id of the task will be the same one as before,
and there will be two kbs for the old and the new tasks with the same scanid.

This patch ensure that there is no kb in redis in used with the same scan id,
and also it will stop the scan in case it is still running.

This first commit add a function to check for kbs with the given scan id.
  • Loading branch information
jjnicola committed Aug 25, 2022
1 parent 0772e48 commit 8fcff19
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ospd_openvas/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,25 @@ def find_kb_database_by_scan_id(

return None

def check_consistency(self, scan_id) -> Tuple[Optional[KbDB], int]:
"""Check if the current scan id already exists in a kb.
Return a tuple with the kb or none, and an error code, being 0 if
the db is clean, -1 on old finished scan, -2 on still running scan.
"""
err = 0

kb = self.find_kb_database_by_scan_id(scan_id)
current_status = None
if kb:
current_status = kb.get_status(scan_id)
if current_status == "finished":
err = -1
elif current_status == "stop_all" or current_status == "ready":
err = -2

return (kb, err)

def release_database(self, database: BaseDB):
self.release_database_by_index(database.index)
database.flush()
Expand Down

0 comments on commit 8fcff19

Please sign in to comment.