Skip to content

Commit 3978e37

Browse files
committed
Added more checks to detect invalid task
1 parent 4d8ae5f commit 3978e37

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/cuckoo/core/plugins.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ class RunProcessing(object):
136136

137137
def __init__(self, task_id):
138138
"""@param task_id: ID of the analyses to process."""
139-
self.task = Database().view_task(task_id).to_dict()
139+
vtask = Database().view_task(task_id)
140+
if not vtask:
141+
raise Exception("Task id does not exist")
142+
self.task = vtask.to_dict()
140143
self.analysis_path = os.path.join(CUCKOO_ROOT, "storage", "analyses", str(task_id))
141144
self.cfg = Config(cfg=os.path.join(CUCKOO_ROOT, "conf", "processing.conf"))
142145

utils/process.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import argparse
1111

1212
logging.basicConfig(level=logging.INFO)
13-
log = logging.getLogger()
13+
log = logging.getLogger(__name__)
1414

1515
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), ".."))
1616

@@ -21,7 +21,11 @@
2121
from lib.cuckoo.core.startup import init_modules
2222

2323
def do(aid, report=False):
24-
results = RunProcessing(task_id=aid).run()
24+
try:
25+
results = RunProcessing(task_id=aid).run()
26+
except Exception as e:
27+
log.error(e)
28+
return
2529
RunSignatures(results=results).run()
2630

2731
if report:
@@ -64,7 +68,16 @@ def main():
6468
time.sleep(5)
6569

6670
else:
67-
do(args.id, report=args.report)
71+
try:
72+
task_id = int(args.id)
73+
except ValueError:
74+
log.error("Invalid task id value")
75+
return
76+
log.info("Processing analysis data for Task #%d", task_id)
77+
try:
78+
do(task_id, report=args.report)
79+
except:
80+
log.exception("Exception when processing a task.")
6881

6982

7083
if __name__ == "__main__":

0 commit comments

Comments
 (0)