summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xkernel-check.py2
-rw-r--r--lib/kernellib.py77
-rwxr-xr-xtools/cron.py8
4 files changed, 41 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index 4869765..7fae12d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
*~
*#
tools/tmp
+tools/cron.log
+dev
diff --git a/kernel-check.py b/kernel-check.py
index ffa8a53..a1ab21d 100755
--- a/kernel-check.py
+++ b/kernel-check.py
@@ -234,7 +234,7 @@ def print_cve(cveid):
#TODO print cve.refs
for i, string in enumerate(textwrap.wrap('"%s"' % cve.desc ,
- (term[1] - 14))):
+ (term[1] - 15))):
if i is 0:
info('Desc : %s' % string)
else:
diff --git a/lib/kernellib.py b/lib/kernellib.py
index 0bc4044..bc979cd 100644
--- a/lib/kernellib.py
+++ b/lib/kernellib.py
@@ -5,7 +5,6 @@
from __future__ import with_statement
from contextlib import closing
-import xml.etree.cElementTree as et
import cStringIO
import datetime
import inspect
@@ -15,6 +14,7 @@ import os
import portage
import re
import urllib
+import xml.etree.cElementTree
ARCHES = [
@@ -47,7 +47,7 @@ KERNEL_TYPES = [
'vserver', 'win4lin', 'wolk-dev', 'wolk', 'xbox', 'xen', 'xfs'
]
-VERSION = '0.3.9'
+VERSION = '0.3.10'
DEBUG = False
FILEPATH = os.path.dirname(os.path.realpath(__file__))
PORTDIR = portage.settings['PORTDIR']
@@ -63,6 +63,7 @@ def BUG_ON(msg):
print 'DEBUG line %s in %s(): %s' % (inspect.stack()[1][2],
inspect.stack()[1][3], msg)
+
class Evaluation:
"""Evaluation class
@@ -79,7 +80,7 @@ class Evaluation:
self.unaffected = list()
-class Comparison:
+class Comparison: #TODO Check if deprecated
"""Comparison class
"""
@@ -118,11 +119,11 @@ class Cve:
def __init__(self, cve):
self.cve = cve
- def __eq__(self, other):
- return (self.cve == other.cve) #FIXME is this enough?
+ def __eq__(self, diff):
+ return (self.cve == diff.cve) #FIXME is this enough?
- def __ne__(self, other):
- return not self.__eq__(other)
+ def __ne__(self, diff):
+ return not self.__eq__(diff)
class Genpatch:
@@ -146,16 +147,16 @@ class Genpatch:
return 'extras'
- def __eq__(self, other):
- if self.kernel == other.kernel:
+ def __eq__(self, diff):
+ if self.kernel == diff.kernel:
return (''.join((str(self.base), str(self.extras), self.version))
- == ''.join((str(other.base), str(other.extras), other.version)))
+ == ''.join((str(diff.base), str(diff.extras), diff.version)))
else:
return False
- def __ne__(self, other):
- return not self.__eq__(other)
+ def __ne__(self, diff):
+ return not self.__eq__(diff)
class Kernel:
@@ -174,14 +175,15 @@ class Kernel:
return str(self.version + '-' + self.source + '-' + self.revision)
- def __eq__(self, other):
- return (''.join((self.revision, self.source, self.version,
- str(self.genpatch))) == ''.join((other.revision,
- other.source, other.version, str(other.genpatch))))
+ def __eq__(self, diff):
+ return (''.join((self.revision, self.source,
+ self.version, str(self.genpatch)))
+ == ''.join((diff.revision, diff.source,
+ diff.version, str(diff.genpatch))))
- def __ne__(self, other):
- return not self.__eq__(other)
+ def __ne__(self, diff):
+ return not self.__eq__(diff)
class Vulnerability:
@@ -199,11 +201,11 @@ class Vulnerability:
def __init__(self, bugid):
self.bugid = bugid
- def __eq__(self, other):
- return (self.bugid == other.bugid) #FIXME is this enough?
+ def __eq__(self, diff):
+ return (self.bugid == diff.bugid) #FIXME is this enough?
- def __ne__(self, other):
- return not self.__eq__(other)
+ def __ne__(self, diff):
+ return not self.__eq__(diff)
class Interval:
@@ -217,7 +219,6 @@ class Interval:
upper: a string representing the upper boundary of the interval
lower_i: a boolean indicating if the lower boundary is inclusive
upper_i: a boolean indicating if the upper boundary is inclusive
- expand: a boolean indicating if the interval is shadowing other intervals
"""
name = str()
@@ -225,9 +226,8 @@ class Interval:
upper = str()
lower_i = bool()
upper_i = bool()
- expand = str()
- def __init__(self, name, lower, upper, lower_i, upper_i, expand):
+ def __init__(self, name, lower, upper, lower_i, upper_i):
if name == 'linux' or name == 'genpatches':
pass
elif name == 'gp':
@@ -251,13 +251,9 @@ class Interval:
self.lower = lower
self.upper = upper
- self.expand = expand
-
def __repr__(self):
interval = str(self.name)
- if self.expand:
- interval += '+'
interval += ' '
if self.lower and self.lower_i:
interval += '>=%s ' % (self.lower)
@@ -280,7 +276,6 @@ def interval_from_xml(root):
upper = ''
lower_i = False
upper_i = False
- expand = '' #TODO implement
if root.find('lower') is not None:
lower = root.find('lower').text
@@ -290,7 +285,7 @@ def interval_from_xml(root):
upper = root.find('upper').text
upper_i = (root.find('upper').get('inclusive') == 'true')
- return Interval(name, lower, upper, lower_i, upper_i, expand)
+ return Interval(name, lower, upper, lower_i, upper_i)
#TODO Use exceptions
@@ -523,20 +518,18 @@ def read_cve_file(directory, bugid):
try:
with open(filename, 'r+') as xml_data:
memory_map = mmap.mmap(xml_data.fileno(), 0)
- root = et.parse(memory_map).getroot()
+ root = xml.etree.cElementTree.parse(memory_map).getroot()
except IOError:
return None
bugroot = root.find('bug')
vul = Vulnerability(bugroot.find('bugid').text)
- vul.arch = bugroot.find('arch').text
- vul.reported = bugroot.find('reported').text
- vul.reporter = bugroot.find('reporter').text
- vul.status = bugroot.find('status').text
- affectedroot = bugroot.find('affected')
+ for elem in ['arch', 'reported', 'reporter', 'status']:
+ setattr(vul, elem, bugroot.find(elem).text)
+ affectedroot = bugroot.find('affected')
for item in affectedroot:
interval = interval_from_xml(item)
affected.append(interval)
@@ -546,12 +539,10 @@ def read_cve_file(directory, bugid):
for item in root:
if item.tag == 'cve':
cve = Cve(item.find('cve').text)
- cve.desc = item.find('desc').text
- cve.published = item.find('published').text
- cve.refs = item.find('refs').text #FIXME
- cve.severity = item.find('severity').text
- cve.score = item.find('score').text
- cve.vector = item.find('vector').text
+
+ for elem in ['desc', 'published', 'refs',
+ 'severity', 'score', 'vector']:
+ setattr(cve, elem, item.find(elem).text)
cves.append(cve)
vul.cves = cves
diff --git a/tools/cron.py b/tools/cron.py
index d280606..17475ab 100755
--- a/tools/cron.py
+++ b/tools/cron.py
@@ -27,9 +27,9 @@ NOCVEDESC = 'This GENERIC identifier is not specific to any vulnerability. '\
'services to specify when a particular vulnerability element ' \
'does not map to a corresponding CVE entry.'
DELAY = 0.2
-SKIP = True
+SKIP = False
MINYEAR = 2002
-MAXYEAR = 2020
+MAXYEAR = 2012
NVDURL = 'http://nvd.nist.gov/'
BZURL = 'https://bugs.gentoo.org/'
STATE = ['NEW', 'ASSIGNED', 'REOPENED', 'RESOLVED', 'VERIFIED', 'CLOSED']
@@ -38,7 +38,7 @@ BUGORDER = ['bugid', 'reporter', 'reported', 'status', 'arch', 'affected']
CVEORDER = ['cve', 'published', 'desc', 'severity', 'vector', 'score', 'refs']
FILEPATH = os.path.dirname(os.path.realpath(__file__))
PORTDIR = portage.settings['PORTDIR']
-LOGFILE = None #os.path.join(FILEPATH, 'cron.log')
+LOGFILE = os.path.join(FILEPATH, 'cron.log')
DIR = {
'tmp' : os.path.join(FILEPATH, 'tmp'),
'out' : os.path.join(PORTDIR, 'metadata', 'kernel'),
@@ -66,7 +66,7 @@ logging.basicConfig(format='[%(asctime)s] %(levelname)-6s : %(message)s',
def main(argv):
'Main function'
- logging.info('Running cron...')
+ logging.info('Running cron')
current_year = datetime.datetime.now().year
if current_year < MINYEAR or current_year > MAXYEAR: