Skip to content

Commit f56841d

Browse files
committed
Added error checks if API_KEY missing or last_mod is empty
1 parent cf04880 commit f56841d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

database.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import argparse
2626
import html
2727
import json
28+
import os
2829
import re
2930
import sqlite3 as sql
30-
import sys
3131
import time
3232
import traceback
3333
from concurrent.futures import ThreadPoolExecutor
@@ -514,8 +514,11 @@ def update_db(args, thread_objs, populate=False):
514514
if not populate:
515515
print("[*] Updating database...")
516516
with Database(args.database) as db:
517-
last = db.cached_metadata()
518-
extra = f"&lastModStartDate={last}&lastModEndDate={now()}"
517+
try:
518+
last = db.cached_metadata()
519+
extra = f"&lastModStartDate={last}&lastModEndDate={now()}"
520+
except TypeError:
521+
pass
519522
else:
520523
print("[+] Creating database...")
521524

@@ -524,6 +527,9 @@ def update_db(args, thread_objs, populate=False):
524527
resp = cl.get(
525528
f"{URL['nvd'].format('cpes', 0)}" f"&resultsPerPage=1{extra}"
526529
)
530+
if resp.status_code != 200:
531+
print("[!] Error retrieving information from NVD API")
532+
os._exit(-1)
527533
cpes = resp.json()["totalResults"]
528534
resp = cl.get(
529535
f"{URL['nvd'].format('cves', 0)}" f"&resultsPerPage=1{extra}"
@@ -683,9 +689,11 @@ def update_exploitdb(args, thread_objs):
683689
with api.open() as f:
684690
KEY = f.read().strip()
685691
else:
686-
print("[!] NVD API key required in order to retrieve data. "
687-
"Check README.md for more information")
688-
sys.exit(-1)
692+
print(
693+
"[!] NVD API key required in order to retrieve data. "
694+
"Check README.md for more information"
695+
)
696+
os._exit(-1)
689697

690698
thread_objs = (Event(), Event(), Queue())
691699
thread = PopulateDBThread(args.database, *thread_objs)

0 commit comments

Comments
 (0)