summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Weimer <fw@deneb.enyo.de>2010-05-07 20:37:27 +0000
committerFlorian Weimer <fw@deneb.enyo.de>2010-05-07 20:37:27 +0000
commitb29e54f874d59a0394f073d2dd7791a345464eb6 (patch)
tree39be22321e1d6118ffa035a6aa82b37550f8e5cd /lib
parentfbb57fa997ba39a137b23e598e5c57a81c42428d (diff)
parsers.cvelist(): preliminary CVE list parser
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@14626 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib')
-rw-r--r--lib/python/parsers.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/python/parsers.py b/lib/python/parsers.py
index 55987336f8..79c373e791 100644
--- a/lib/python/parsers.py
+++ b/lib/python/parsers.py
@@ -191,6 +191,73 @@ def _annotationdispatcher():
addmessage(messages, file, line, "error", "invalid annotation"))
_annotationdispatcher = _annotationdispatcher()
+List = xcollections.namedtuple("List", "list messages")
+Bug = xcollections.namedtuple("Bug", "file header annotations")
+Header = xcollections.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*$')
+@xpickle.loader("CVE" + FORMAT)
+def cvelist(path, f):
+ lineno = 0
+ headerlineno = None
+ bugs = []
+ messages = []
+ name = desc = 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
+ if line[:1] in " \t":
+ if name is None:
+ addmessage(messages, path, lineno, "error", "header expected")
+ continue
+ _annotationdispatcher(line, path, lineno, messages, anns)
+ else:
+ emit()
+ headerlineno = lineno
+
+ match = _re_cve_header.match(line)
+ if match is None:
+ addmessage(message, path, lineno, "error", "malformed header")
+ name = desc = None
+ continue
+ name, desc = match.groups()
+ if desc:
+ if desc[0] == '(':
+ if desc[-1] <> ')':
+ addmessage(message, path, lineno, "error",
+ "missing ')'")
+ else:
+ desc = desc[1:-1]
+ elif desc[0] == '[':
+ if desc[-1] <> ']':
+ addmessage(message, path, lineno, "error",
+ "missing ']'")
+ else:
+ desc = desc[1:-1]
+
+ emit()
+ return List(tuple(bugs), tuple(messages))
+
def _test():
o = binarypackages("../../data/packages/sid__main_i386_Packages")
assert type(o) == type(())
@@ -200,6 +267,11 @@ def _test():
assert type(o) == type({})
assert "bash" in o
+ xpickle.safeunlink("../../data/CVE/list" + xpickle.EXTENSION)
+ o = cvelist("../../data/CVE/list")
+ for err in o.messages:
+ print "%s:%d: %s: %s" % (err.file, err.line, err.level, err.message)
+
for (line, res, xmsgs) in [
(' - foo <unfixed>',
PackageAnnotation(17, "package", None, "foo", "unfixed", None,

© 2014-2024 Faster IT GmbH | imprint | privacy policy