commit:     f4f55c3a59583336b249e098abffbe75400f2df5
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  9 15:36:07 2017 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Jan  9 15:36:07 2017 +0000
URL:        https://gitweb.gentoo.org/proj/security.git/commit/?id=f4f55c3a

cvetool: Detect missing CVE and catch exception when requesting CVE info

 bin/cvetool | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/bin/cvetool b/bin/cvetool
index d6c2f6d..b8aa5ca 100755
--- a/bin/cvetool
+++ b/bin/cvetool
@@ -15,6 +15,9 @@ URI_BASE = 'https://glsamaker.gentoo.org'
 class CVETool:
     """ Interface to GLSAMaker's CVETool """
 
+    class NotFoundError(RuntimeError):
+        pass
+
     def __init__(self, auth, command, args):
         self.auth = auth
 
@@ -46,7 +49,11 @@ class CVETool:
             sys.exit(1)
 
     def info(self, cve):
-        data = self.json_request('/cve/info/' + cve + '.json')
+        try:
+            data = self.json_request('/cve/info/' + cve + '.json')
+        except self.NotFoundError as e:
+            print('{} not found in Gentoo\'s CVE database!'.format(cve))
+            sys.exit(0)
 
         print('    CVE ID: ' + data['cve_id'])
         print('   Summary: ' + data['summary'])
@@ -107,7 +114,9 @@ class CVETool:
         response, content = client.request(full_uri, method, headers = { 
'Authorization': 'Basic ' + self.auth })
 
         status = response['status']
-        if (status[0] != '2' and status != '304'):
+        if (status == '404'):
+            raise self.NotFoundError(full_uri + ': ' + status)
+        elif (status[0] != '2' and status != '304'):
             raise RuntimeError(full_uri + ': ' + status)
 
         return content.decode('utf-8')

Reply via email to