1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 00:20:08 +00:00

cve-update-db-native: improve metadata parsing

The metadata parser is fragile: first it coerces a bytes() to a str() (so the
string is b'LastModifiedDate:2019...'), assumes the first line is the date, and
then uses a regex to parse (which then includes the trailing quote as part of
the date).

Clean this up by parsing the bytes as UTF-8 (ASCII is probably fine, but this is
safer), iterate through the lines and split on colons to find the right
key/value pair.

(From OE-Core rev: bb4e53af33d6ca1e9346464adbdc1b39c47530f3)

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ross Burton
2019-07-19 21:33:18 +01:00
committed by Richard Purdie
parent 8ec4cd3e2a
commit 297605eec0
+10 -8
View File
@@ -22,7 +22,7 @@ python do_populate_cve_db() {
Update NVD database with json data feed Update NVD database with json data feed
""" """
import sqlite3, urllib, shutil, gzip, re import sqlite3, urllib, shutil, gzip
from datetime import date from datetime import date
BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-" BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
@@ -52,13 +52,15 @@ python do_populate_cve_db() {
req = urllib.request.Request(meta_url) req = urllib.request.Request(meta_url)
if proxy: if proxy:
req.set_proxy(proxy, 'https') req.set_proxy(proxy, 'https')
try: with urllib.request.urlopen(req) as r:
with urllib.request.urlopen(req, timeout=1) as r: for l in r.read().decode("utf-8").splitlines():
date_line = str(r.read().splitlines()[0]) key, value = l.split(":", 1)
last_modified = re.search('lastModifiedDate:(.*)', date_line).group(1) if key == "lastModifiedDate":
except: last_modified = value
cve_f.write('Warning: CVE db update error, CVE data is outdated.\n\n') break
break else:
bb.warn("Cannot parse CVE metadata, update failed")
return
# Compare with current db last modified date # Compare with current db last modified date
c.execute("select DATE from META where YEAR = ?", (year,)) c.execute("select DATE from META where YEAR = ?", (year,))