diff options
author | Thomas Deutschmann <whissi@gentoo.org> | 2017-01-09 16:36:07 +0100 |
---|---|---|
committer | Thomas Deutschmann <whissi@gentoo.org> | 2017-01-09 16:36:07 +0100 |
commit | f4f55c3a59583336b249e098abffbe75400f2df5 (patch) | |
tree | cc1e69a0d252b8ebf066d2c2567d813437da1181 | |
parent | cvetool: Fix TypeError when requesting CVE info for not yet published CVE (diff) | |
download | security-f4f55c3a59583336b249e098abffbe75400f2df5.tar.gz security-f4f55c3a59583336b249e098abffbe75400f2df5.tar.bz2 security-f4f55c3a59583336b249e098abffbe75400f2df5.zip |
cvetool: Detect missing CVE and catch exception when requesting CVE info
-rwxr-xr-x | bin/cvetool | 13 |
1 files 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') |