summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Tropf <asymmail@googlemail.com>2009-06-11 21:57:00 +0200
committerBjoern Tropf <asymmail@googlemail.com>2009-06-11 21:57:00 +0200
commit93196a0526d6df1fea79966c2ac95d58843e3524 (patch)
treeb3590f00b9b4c6c09e2055e57e0c0b7770c8c1e1
parentAdd kernel class; Fix some bugs (diff)
downloadkernel-check-93196a0526d6df1fea79966c2ac95d58843e3524.tar.gz
kernel-check-93196a0526d6df1fea79966c2ac95d58843e3524.tar.bz2
kernel-check-93196a0526d6df1fea79966c2ac95d58843e3524.zip
Some bug fixes
-rw-r--r--TODO1
-rwxr-xr-xcollector.py11
-rwxr-xr-xkernel-check.py2
-rwxr-xr-xkernellib.py54
4 files changed, 38 insertions, 30 deletions
diff --git a/TODO b/TODO
index e526dd7..0cc35d7 100644
--- a/TODO
+++ b/TODO
@@ -11,6 +11,7 @@ Clean code
- Use more telling variables
- Rework Descriptions
- Remove unused code/find better ways
+- Add error handling
Documentation
=============
diff --git a/collector.py b/collector.py
index 71edf6f..4fc76ec 100755
--- a/collector.py
+++ b/collector.py
@@ -82,10 +82,11 @@ def main(argv):
read_patches.append(item)
new_items += 1
- lib.write_genpatch_file(folder['out'], read_patches)
- print('Added %i new genpatches!\n' % new_items)
+ if (new_items):
+ lib.write_genpatch_file(folder['out'], read_patches)
+ print('Added %i new genpatches!' % new_items)
- print('Receiving the latest xml file from the nvd...')
+ print('\nReceiving the latest xml file from the nvd...')
lib.receive_nvd_recent(folder['nvd'])
if not SKIP:
@@ -99,9 +100,9 @@ def main(argv):
lib.receive_bugzilla_list(folder['temp'])
buglist = lib.parse_bugzilla_list(folder['temp'])
- print('Found %i kernel vulnerabilities!\n' % len(buglist))
+ print('Found %i kernel vulnerabilities!' % len(buglist))
- print('Creating the xml files...')
+ print('\nCreating the xml files...')
for item in buglist:
lib.receive_bugzilla_bug(folder['bug'], item)
vul = lib.parse_bugzilla_dict(folder['bug'], item)
diff --git a/kernel-check.py b/kernel-check.py
index 92074bf..c3f080c 100755
--- a/kernel-check.py
+++ b/kernel-check.py
@@ -61,7 +61,7 @@ def main(argv):
genpatch = lib.get_genpatch(lib.read_genpatch_file('out'), kernel)
if genpatch is not None:
- info('Integrated genpatch: %s' % color('GOOD', '%s %s' % (genpatch.version, genpatch.want)))
+ info('Integrated genpatch: %s' % color('GOOD', '%s %s' % (genpatch.version, repr(genpatch))))
else:
warn('No genpatch information found!')
diff --git a/kernellib.py b/kernellib.py
index c22a55e..688e282 100755
--- a/kernellib.py
+++ b/kernellib.py
@@ -41,7 +41,7 @@ REGEX = {
'wb_match' : re.compile(r'\s*\[\s*([^ +<=>]+)\s*(\+?)\s*([<=>]{1,2})\s*([^ <=>\]]+)\s*(?:([<=>]{1,2})\s*([^ \]]+))?\s*\]\s*(.*)'),
'wb_version' : re.compile(r'^(?:\d{1,2}\.){0,3}\d{1,2}(?:[-_](?:r|rc)?\d{1,2})*$'),
- 'version' : re.compile(r'^((?:\d{1,2}\.){0,3}\d{1,2})(-.*)?$'),
+ 'version' : re.compile(r'^((?:\d{1,2}\.){0,4}\d{1,2})(-.*)?$'),
'rcd' : re.compile(r'^rc\d{1,3}$'),
'gitd' : re.compile(r'^git(\d{1,3})$'),
'rd' : re.compile(r'^r\d{1,3}$')
@@ -96,12 +96,20 @@ class Genpatch:
extras = bool()
kernel = None
version = str()
- want = str() #TODO use __repr__
def __init__(self, version):
self.version = version
+ def __repr__(self):
+ if self.base and self.extras:
+ return 'base extras'
+ if self.base:
+ return 'base'
+ if self.extras:
+ return 'extras'
+
+
#FIXME
def __eq__(self, other):
return (''.join((str(self.base), str(self.extras),
@@ -127,6 +135,10 @@ class Kernel:
self.source = source
+ def __repr__(self):
+ return str(self.version + '-' + self.source + '-' + self.revision)
+
+
def __eq__(self, other):
return (''.join((self.revision, self.source, self.version))
== ''.join((other.revision, other.source, other.version)))
@@ -190,7 +202,7 @@ class Interval:
def __repr__(self):
- interval = str((self.name))
+ interval = str(self.name)
if self.expand:
interval += '+'
interval += ' '
@@ -218,7 +230,7 @@ class Interval:
if getattr(self, boundary):
node = et.SubElement(intnode, boundary)
node.text = getattr(self, boundary)
- node.set('inclusive', str(getattr(self, boundary + '_inclusive')).lower())
+ node.set('inclusive', str(getattr(self, boundary + '_i')).lower())
return intnode
@@ -274,11 +286,9 @@ def read_genpatch_file(directory):
root = et.parse(memory_map).getroot()
for tree in root:
- #FIXME Rework
- kernel = Kernel(tree.get('kernels'))
- kernel.revision = tree.get('kernelr')
- kernel.version = tree.get('kernelv')
-
+ kernel = extract_version(tree.get('kernel'))
+ if kernel is None:
+ continue
genpatch = Genpatch(tree.get('version'))
genpatch.kernel = kernel
genpatch.base = (tree.get('base') == 'true')
@@ -297,10 +307,7 @@ def write_genpatch_file(directory, patches):
for item in patches:
genpatch = et.SubElement(root, 'genpatch')
- #FIXME Rework
- genpatch.set('kernelr', str(item.kernel.revision))
- genpatch.set('kernels', str(item.kernel.source))
- genpatch.set('kernelv', str(item.kernel.version))
+ genpatch.set('kernel', repr(item.kernel))
genpatch.set('version', item.version)
genpatch.set('base', str(item.base).lower())
genpatch.set('extras', str(item.extras).lower())
@@ -314,13 +321,6 @@ def get_genpatch(patches, kernel):
for item in patches:
if item.kernel == kernel: #FIXME Why does 'is' not work?
- #TODO use __repr__
- if item.base:
- item.want = 'base'
- if item.extras:
- item.want = 'extras'
- if item.base and item.extras:
- item.want = 'base extras'
return item
return None
@@ -343,7 +343,10 @@ def parse_bugzilla_dict(directory, bugid):
'Returns a vulnerability class containing information about a bugzilla bug'
filename = os.path.join(directory, bugid)
- root = et.parse(open(filename, 'r')).getroot()[0] #TODO mmap
+
+ with open(filename, 'r+') as xml_data:
+ memory_map = mmap.mmap(xml_data.fileno(), 0)
+ root = et.parse(memory_map).getroot()[0]
vul = Vulnerability(bugid)
@@ -351,7 +354,7 @@ def parse_bugzilla_dict(directory, bugid):
vul.cvelist = extract_cves(root.find('short_desc').text)
if not vul.cvelist:
error('Invalid cve for bugid [%s]' % root.find('bug_id').text)
- error('-> %s' % root.find(item).text)
+ error('-> %s' % root.find('short_desc').text)
vul.interval = from_whiteboard(root.find('status_whiteboard').text)
#TODO Error
@@ -516,7 +519,7 @@ def write_cve_file(directory, vul):
item.to_xml(affectedroot)
else:
error('Whiteboard for bugid [%s]' % vul.bugid)
- error('-> %s' % vul.interval)
+ error('-> %s' % vul.interval) #FIXME
else:
node = et.SubElement(bugroot, element)
node.text = getattr(vul, element)
@@ -646,6 +649,7 @@ def extract_version(release):
match = REGEX['version'].match(release)
if not match:
+ error('Release %s does not contain any valid kernel information' % release)
return None
version, rest = match.groups()
@@ -655,7 +659,9 @@ def extract_version(release):
kernel.version = version
for elem in (rest or '').split('-'):
- if REGEX['rcd'].match(elem):
+ if elem == 'sources':
+ pass
+ elif REGEX['rcd'].match(elem):
kernel.version += '_' + elem
elif REGEX['gitd'].match(elem):
kernel.source = 'git'