summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Marko <peter.marko@siemens.com>2023-11-27 20:55:36 +0100
committerSteve Sakoman <steve@sakoman.com>2024-01-10 03:57:03 -1000
commit1a94a6426816b6e574ec354025b273369faaebeb (patch)
tree3a558126e9fd0f8f574e9c1b51e6c889c02b53c9
parent982ab5d6d98c027028717f8c9a1c45e5ce7ff35c (diff)
downloadpoky-1a94a6426816b6e574ec354025b273369faaebeb.tar.gz
cve-update-nvd2-native: make number of fetch attemtps configurable
Sometimes NVD servers are unstable and return too many errors. Last time we increased number of attempts from 3 to 5, but further increasing is not reasonable as in normal case too many retries is just abusive. Keep retries low as default and allow to increase as needed. (From OE-Core rev: ee2a6ade703317d09f7df60ef7ce300d8f868f54) Signed-off-by: Peter Marko <peter.marko@siemens.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 6b6fd8043d83b99000054ab6ad2c745d07c6bcc1) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-core/meta/cve-update-nvd2-native.bb10
1 files changed, 7 insertions, 3 deletions
diff --git a/meta/recipes-core/meta/cve-update-nvd2-native.bb b/meta/recipes-core/meta/cve-update-nvd2-native.bb
index 64a96a46f0..dab0b69edc 100644
--- a/meta/recipes-core/meta/cve-update-nvd2-native.bb
+++ b/meta/recipes-core/meta/cve-update-nvd2-native.bb
@@ -26,6 +26,9 @@ NVDCVE_API_KEY ?= ""
26# Use a negative value to skip the update 26# Use a negative value to skip the update
27CVE_DB_UPDATE_INTERVAL ?= "86400" 27CVE_DB_UPDATE_INTERVAL ?= "86400"
28 28
29# Number of attmepts for each http query to nvd server before giving up
30CVE_DB_UPDATE_ATTEMPTS ?= "5"
31
29CVE_DB_TEMP_FILE ?= "${CVE_CHECK_DB_DIR}/temp_nvdcve_2.db" 32CVE_DB_TEMP_FILE ?= "${CVE_CHECK_DB_DIR}/temp_nvdcve_2.db"
30 33
31CVE_CHECK_DB_FILE ?= "${CVE_CHECK_DB_DIR}/nvdcve_2.db" 34CVE_CHECK_DB_FILE ?= "${CVE_CHECK_DB_DIR}/nvdcve_2.db"
@@ -111,7 +114,7 @@ def cleanup_db_download(db_file, db_tmp_file):
111 if os.path.exists(db_tmp_file): 114 if os.path.exists(db_tmp_file):
112 os.remove(db_tmp_file) 115 os.remove(db_tmp_file)
113 116
114def nvd_request_next(url, api_key, args): 117def nvd_request_next(url, attempts, api_key, args):
115 """ 118 """
116 Request next part of the NVD dabase 119 Request next part of the NVD dabase
117 """ 120 """
@@ -127,7 +130,7 @@ def nvd_request_next(url, api_key, args):
127 request.add_header("apiKey", api_key) 130 request.add_header("apiKey", api_key)
128 bb.note("Requesting %s" % request.full_url) 131 bb.note("Requesting %s" % request.full_url)
129 132
130 for attempt in range(5): 133 for attempt in range(attempts):
131 try: 134 try:
132 r = urllib.request.urlopen(request) 135 r = urllib.request.urlopen(request)
133 136
@@ -183,10 +186,11 @@ def update_db_file(db_tmp_file, d, database_time):
183 index = 0 186 index = 0
184 url = d.getVar("NVDCVE_URL") 187 url = d.getVar("NVDCVE_URL")
185 api_key = d.getVar("NVDCVE_API_KEY") or None 188 api_key = d.getVar("NVDCVE_API_KEY") or None
189 attempts = int(d.getVar("CVE_DB_UPDATE_ATTEMPTS"))
186 190
187 while True: 191 while True:
188 req_args['startIndex'] = index 192 req_args['startIndex'] = index
189 raw_data = nvd_request_next(url, api_key, req_args) 193 raw_data = nvd_request_next(url, attempts, api_key, req_args)
190 if raw_data is None: 194 if raw_data is None:
191 # We haven't managed to download data 195 # We haven't managed to download data
192 return False 196 return False