[Secure-testing-commits] r14648 - in lib/python: sectracker sectracker_test
Florian Weimer
fw at alioth.debian.org
Sat May 8 18:23:59 UTC 2010
Author: fw
Date: 2010-05-08 18:23:58 +0000 (Sat, 08 May 2010)
New Revision: 14648
Modified:
lib/python/sectracker/parsers.py
lib/python/sectracker_test/test_parsers.py
Log:
sectracker.parsers.dsalist(): DSA file parser
Modified: lib/python/sectracker/parsers.py
===================================================================
--- lib/python/sectracker/parsers.py 2010-05-08 18:22:31 UTC (rev 14647)
+++ lib/python/sectracker/parsers.py 2010-05-08 18:23:58 UTC (rev 14648)
@@ -185,65 +185,92 @@
Bug = _namedtuple("Bug", "file header annotations")
Header = _namedtuple("Header", "line name description")
-def _cveuniquename(line, anns):
- bug = 0
- for ann in anns:
- if ann.type == "package" and ann.debian_bugs:
- bug = ann.debian_bugs[0]
- break
- return "TEMP-%07d-%06d" % (bug, line)
-
-_re_cve_header = re.compile(r'^(CVE-\d{4}-(?:\d{4}|XXXX))\s+(.*?)\s*$')
- at _xpickle.loader("CVE" + FORMAT)
-def cvelist(path, f):
+def _parselist(path, f, parseheader, finish):
lineno = 0
headerlineno = None
bugs = []
diag = sectracker.diagnostics.Diagnostics()
- name = desc = None
+ header = None
anns = []
- def emit():
- if name is None:
- return
-
- if name[-1] == "X":
- name1 = _cveuniquename(headerlineno, anns)
- else:
- name1 = name
- bugs.append(Bug(path, Header(headerlineno, name1, desc), tuple(anns)))
- del anns[:]
-
for line in f.readlines():
lineno += 1
diag.setlocation(path, lineno)
if line[:1] in " \t":
- if name is None:
+ if header is None:
diag.error("header expected")
continue
_annotationdispatcher(line, diag, anns)
else:
- emit()
+ if header is not None:
+ bugs.append(finish(header, headerlineno, anns, diag))
+ del anns[:]
headerlineno = lineno
- match = _re_cve_header.match(line)
- if match is None:
+ header = parseheader(line)
+ if header is None:
diag.error("malformed header")
- name = desc = None
continue
- name, desc = match.groups()
- if desc:
- if desc[0] == '(':
- if desc[-1] <> ')':
- diag.error("error", "missing ')'")
- else:
- desc = desc[1:-1]
- elif desc[0] == '[':
- if desc[-1] <> ']':
- diag.error("missing ']'")
- else:
- desc = desc[1:-1]
- emit()
+ if header is not None:
+ finish(header, headerlineno, anns, diag)
return List(tuple(bugs), diag.messages())
+
+ at _xpickle.loader("CVE" + FORMAT)
+def cvelist(path, f):
+ re_header = re.compile(r'^(CVE-\d{4}-(?:\d{4}|XXXX))\s+(.*?)\s*$')
+ def parseheader(line):
+ match = re_header.match(line)
+ if match is None:
+ return None
+ name, desc = match.groups()
+ if desc:
+ if desc[0] == '(':
+ if desc[-1] <> ')':
+ diag.error("error", "missing ')'")
+ else:
+ desc = desc[1:-1]
+ elif desc[0] == '[':
+ if desc[-1] <> ']':
+ diag.error("missing ']'")
+ else:
+ desc = desc[1:-1]
+ return (name, desc)
+ def cveuniquename(line, anns):
+ bug = 0
+ for ann in anns:
+ if ann.type == "package" and ann.debian_bugs:
+ bug = ann.debian_bugs[0]
+ break
+ return "TEMP-%07d-%06d" % (bug, line)
+ def finish(header, headerlineno, anns, diag):
+ name, desc = header
+ if name[-1] == "X":
+ name1 = cveuniquename(headerlineno, anns)
+ else:
+ name1 = name
+ return Bug(path, Header(headerlineno, name1, desc), tuple(anns))
+ return _parselist(path, f, parseheader, finish)
+
+def _checkrelease(anns, diag, kind):
+ for ann in anns:
+ if ann.type == "package" and ann.release is None:
+ diag.error("release annotation required in %s file" % kind,
+ line=ann.line)
+
+ at _xpickle.loader("DSA" + FORMAT)
+def dsalist(path, f):
+ re_header = re.compile(r'^\[(\d\d) ([A-Z][a-z][a-z]) (\d{4})\] '
+ + r'(DSA-\d+(?:-\d+)?)\s+'
+ + r'(.*?)\s*$')
+ def parseheader(line):
+ match = re_header.match(line)
+ if match is None:
+ return None
+ return match.groups()
+ def finish(header, headerlineno, anns, diag):
+ d, m, y, name, desc = header
+ _checkrelease(anns, diag, "DSA")
+ return Bug(path, Header(headerlineno, name, None), tuple(anns))
+ return _parselist(path, f, parseheader, finish)
Modified: lib/python/sectracker_test/test_parsers.py
===================================================================
--- lib/python/sectracker_test/test_parsers.py 2010-05-08 18:22:31 UTC (rev 14647)
+++ lib/python/sectracker_test/test_parsers.py 2010-05-08 18:23:58 UTC (rev 14648)
@@ -30,6 +30,11 @@
for err in o.messages:
print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)
+safeunlink("../../data/DSA/list" + EXTENSION)
+o = dsalist("../../data/DSA/list")
+for err in o.messages:
+ print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)
+
Message = sectracker.diagnostics.Message
for (line, res, xmsgs) in [
(' - foo <unfixed>',
More information about the Secure-testing-commits
mailing list