Skip to content

Commit 8fcff19

Browse files
committed
Fix: Stop and clean finished/running openvas process before resumming 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.
1 parent 0772e48 commit 8fcff19

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ospd_openvas/db.py

+19
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,25 @@ def find_kb_database_by_scan_id(
648648

649649
return None
650650

651+
def check_consistency(self, scan_id) -> Tuple[Optional[KbDB], int]:
652+
"""Check if the current scan id already exists in a kb.
653+
654+
Return a tuple with the kb or none, and an error code, being 0 if
655+
the db is clean, -1 on old finished scan, -2 on still running scan.
656+
"""
657+
err = 0
658+
659+
kb = self.find_kb_database_by_scan_id(scan_id)
660+
current_status = None
661+
if kb:
662+
current_status = kb.get_status(scan_id)
663+
if current_status == "finished":
664+
err = -1
665+
elif current_status == "stop_all" or current_status == "ready":
666+
err = -2
667+
668+
return (kb, err)
669+
651670
def release_database(self, database: BaseDB):
652671
self.release_database_by_index(database.index)
653672
database.flush()

0 commit comments

Comments
 (0)