Skip to contentSkip to conversation

cve-update-db-native: use os.path.join instead of +

PATCH In review Ross Burton 3 participants 6 messages Jul 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 cve-update-db-native: use os.path.join instead of +

---
 meta/recipes-core/meta/cve-update-db-native.bb | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/recipes-core/meta/cve-update-db-native.bb +4 -4
index 3519beae5fb..9047513dbdf 100644
@@ -29,11 +29,11 @@ python do_populate_cve_db() {
     BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
     YEAR_START = 2002
 
-    db_dir = d.getVar("DL_DIR") + '/CVE_CHECK'
-    db_file = db_dir + '/nvdcve_1.0.db'
-    json_tmpfile = db_dir + '/nvd.json.gz'
+    db_dir = os.path.join(d.getVar("DL_DIR"), 'CVE_CHECK')
+    db_file = os.path.join(db_dir, 'nvdcve_1.0.db')
+    json_tmpfile = os.path.join(db_dir, 'nvd.json.gz')
     proxy = d.getVar("https_proxy")
-    cve_f = open(d.getVar("TMPDIR") + '/cve_check', 'a')
+    cve_f = open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a')
 
     if not os.path.isdir(db_dir):
         os.mkdir(db_dir)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/3 cve-update-db: actually inherit native

The recipe was called -native but didn't inherit native.

---
 meta/recipes-core/meta/cve-update-db-native.bb | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
meta/recipes-core/meta/cve-update-db-native.bb +1 -2
index 9047513dbdf..cabbde5066c 100644
@@ -2,9 +2,8 @@ SUMMARY = "Updates the NVD CVE database"
 LICENSE = "MIT"
 
 INHIBIT_DEFAULT_DEPS = "1"
-PACKAGES = ""
 
-inherit nopackages
+inherit native
 
 deltask do_unpack
 deltask do_patch
Signature · 1 line
2.20.1
#2 lore raw

PATCH 3/3 cve-update-db: refresh once every 24 hours

In reply to Ross Burton

Check the mtime of the database before updating, and if it's less than 24 hours ago don't refresh. This saves the HTTP fetches to determine if the data has been updated.

---
 meta/recipes-core/meta/cve-update-db-native.bb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
meta/recipes-core/meta/cve-update-db-native.bb +6 -1
index cabbde5066c..2afca94fc6b 100644
@@ -22,7 +22,7 @@ python do_populate_cve_db() {
     Update NVD database with json data feed
     """
 
-    import sqlite3, urllib, shutil, gzip, re
+    import sqlite3, urllib, shutil, gzip, re, time
     from datetime import date
 
     BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
@@ -37,6 +37,11 @@ python do_populate_cve_db() {
     if not os.path.isdir(db_dir):
         os.mkdir(db_dir)
 
+    expiry = time.time() - (60*60*24) # This time yesterday
+    if os.path.exists(db_file) and expiry < os.path.getmtime(db_file):
+        bb.note("CVE data updated less than 24 hours ago, not refreshing. Delete %s to force update." % db_file)
+        return
+
     # Connect to database
     conn = sqlite3.connect(db_file)
     c = conn.cursor()
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH 3/3] cve-update-db: refresh once every 24 hours

Quoted 23 lines · Ross Burton

Check the mtime of the database before updating, and if it's less than 24 hours ago don't refresh. This saves the HTTP fetches to determine if the data has been updated.

---
 meta/recipes-core/meta/cve-update-db-native.bb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
meta/recipes-core/meta/cve-update-db-native.bb +1 -1
index cabbde5066c..2afca94fc6b 100644
@@ -22,7 +22,7 @@ python do_populate_cve_db() {
     Update NVD database with json data feed
     """
 
-    import sqlite3, urllib, shutil, gzip, re
+    import sqlite3, urllib, shutil, gzip, re, time
     from datetime import date
 
     BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"

meta/recipes-core/meta/cve-update-db-native.bb python do_populate_cve_db() { · line 43

Quoted 7 lines
meta/recipes-core/meta/cve-update-db-native.bb +4 -0
@@ -37,6 +37,11 @@ python do_populate_cve_db() {
     if not os.path.isdir(db_dir):
         os.mkdir(db_dir)
 
+    expiry = time.time() - (60*60*24) # This time yesterday
+    if os.path.exists(db_file) and expiry < os.path.getmtime(db_file):
+        bb.note("CVE data updated less than 24 hours ago, not refreshing. Delete %s to force update." % db_file)
+        return

Any reason this can't be configurable?

- armin

Quoted 4 lines
meta/recipes-core/meta/cve-update-db-native.bb +1 -0
+
     # Connect to database
     conn = sqlite3.connect(db_file)
     c = conn.cursor()
#4 lore raw

Re: [PATCH 3/3] cve-update-db: refresh once every 24 hours

Quoted 1 line · On Thu, 18 Jul 2019 at 23:31, akuster808 <[email protected]> wrote:

Any reason this can't be configurable?

The raw data isn't updated a lot more frequently than that as far as I'm aware. Also I may retract this and replace it with simply using DATE as the hash because otherwise the class causes constant rebuilds of the world.

Ross

#5 lore raw

✗ patchtest: failure for "cve-update-db-native: use os.p..." and 2 more

In reply to Ross Burton

== Series Details ==

Series: "cve-update-db-native: use os.p..." and 2 more
Revision: 1
URL : https://patchwork.openembedded.org/series/18753/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 4a69bf5ae3)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---

Guidelines:     https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe