Merge lp:~cprov/launchpad/cve-2014 into lp:launchpad

Proposed by Celso Providelo
Status: Merged
Merged at revision: 16954
Proposed branch: lp:~cprov/launchpad/cve-2014
Merge into: lp:launchpad
Diff against target: 167 lines (+75/-11)
6 files modified
database/schema/patch-2209-55-0.sql (+17/-0)
doc/bug-export.rnc (+1/-1)
lib/lp/app/validators/cve.py (+29/-2)
lib/lp/app/validators/tests/test_validators.py (+2/-1)
lib/lp/bugs/doc/cve.txt (+21/-0)
lib/lp/bugs/model/cve.py (+5/-7)
To merge this branch: bzr merge lp:~cprov/launchpad/cve-2014
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+209126@code.launchpad.net

Description of the change

Supporting 2014-format CVE references (sequence identifier longer than 4-digits).

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

There's also a cvename regex defined in doc/bug-export.rnc that you might want to fix.

Did you check that update-cve.py will correctly import the extended format?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'database/schema/patch-2209-55-0.sql'
2--- database/schema/patch-2209-55-0.sql 1970-01-01 00:00:00 +0000
3+++ database/schema/patch-2209-55-0.sql 2014-03-05 02:19:53 +0000
4@@ -0,0 +1,17 @@
5+-- Copyright 2014 Canonical Ltd. This software is licensed under the
6+-- GNU Affero General Public License version 3 (see the file LICENSE).
7+
8+SET client_min_messages=ERROR;
9+
10+CREATE OR REPLACE FUNCTION valid_cve(text) RETURNS boolean
11+ LANGUAGE plpythonu IMMUTABLE STRICT
12+ AS $_$
13+ import re
14+ name = args[0]
15+ pat = r"^(19|20)\d{2}-\d{4,}$"
16+ if re.match(pat, name):
17+ return 1
18+ return 0
19+$_$;
20+
21+INSERT INTO LaunchpadDatabaseRevision VALUES (2209, 55, 0);
22
23=== modified file 'doc/bug-export.rnc'
24--- doc/bug-export.rnc 2012-07-07 15:49:23 +0000
25+++ doc/bug-export.rnc 2014-03-05 02:19:53 +0000
26@@ -7,7 +7,7 @@
27 boolean = "True" | "False"
28 lpname = xsd:string { pattern = "[a-z0-9][a-z0-9\+\.\-]*" }
29 lpbugname = xsd:string { pattern = "[a-z][a-z0-9\+\.\-]*" }
30-cvename = xsd:string { pattern = "(19|20)[0-9][0-9]-[0-9][0-9][0-9][0-9]" }
31+cvename = xsd:string { pattern = "(19|20)[0-9]{2}-[0-9]{4,}" }
32 non_empty_text = xsd:string { minLength = "1" }
33
34 # XXX: jamesh 2006-04-11 bug=105401:
35
36=== modified file 'lib/lp/app/validators/cve.py'
37--- lib/lp/app/validators/cve.py 2009-06-25 05:30:52 +0000
38+++ lib/lp/app/validators/cve.py 2014-03-05 02:19:53 +0000
39@@ -6,9 +6,36 @@
40 import re
41
42
43+cveseq_regexp = r'(19|20)\d{2}\-\d{4,}'
44+CVEREF_PATTERN = re.compile(r'(CVE|CAN)-(%s)' % cveseq_regexp)
45+
46+
47 def valid_cve(name):
48- pat = r"^(19|20)\d\d-\d{4}$"
49+ """Validate CVE identification.
50+
51+ Until 2014 CVE sequence had to be smaller 4 digits (<= 9999):
52+
53+ >>> valid_cve('1999-1234')
54+ True
55+ >>> valid_cve('2014-9999')
56+ True
57+
58+ And leading zeros were required for sequence in [1-999]:
59+
60+ >>> valid_cve('2014-999')
61+ False
62+ >>> valid_cve('2014-0999')
63+ True
64+
65+ From 2014 and on, sequence can be any sequence of digits greater or
66+ equal to 4 digits:
67+
68+ >>> valid_cve('2014-19999')
69+ True
70+ >>> valid_cve('2014-99999999')
71+ True
72+ """
73+ pat = r"^%s" % cveseq_regexp
74 if re.match(pat, name):
75 return True
76 return False
77-
78
79=== modified file 'lib/lp/app/validators/tests/test_validators.py'
80--- lib/lp/app/validators/tests/test_validators.py 2011-12-28 17:03:06 +0000
81+++ lib/lp/app/validators/tests/test_validators.py 2014-03-05 02:19:53 +0000
82@@ -27,7 +27,8 @@
83 suite.addTest(
84 DocTestSuite(validators, optionflags=ELLIPSIS | NORMALIZE_WHITESPACE))
85
86- from lp.app.validators import email, name, url, version
87+ from lp.app.validators import cve, email, name, url, version
88+ suite.addTest(suitefor(cve))
89 suite.addTest(suitefor(email))
90 suite.addTest(suitefor(name))
91 suite.addTest(suitefor(url))
92
93=== modified file 'lib/lp/bugs/doc/cve.txt'
94--- lib/lp/bugs/doc/cve.txt 2012-08-07 02:31:56 +0000
95+++ lib/lp/bugs/doc/cve.txt 2014-03-05 02:19:53 +0000
96@@ -99,6 +99,27 @@
97 True
98 >>> b.unlinkCVE(cve, user=no_priv)
99
100+== 2014 CVE identification format changes =
101+
102+Since 2014, CVEs can have an identifier (sequence) longer than 4-digits.
103+
104+CVEs creation accepts 2014 format:
105+
106+ >>> cve_2014 = cveset.new(sequence="2014-999999",
107+ ... description="A new-style CVE sequence", status=CveStatus.ENTRY,
108+ ... )
109+ >>> cve_2014.displayname
110+ u'CVE-2014-999999'
111+
112+Text references to CVEs using 2014 format can be found:
113+
114+ >>> b.findCvesInText('''
115+ ... This bug is related to CVE-2014-999999
116+ ... ''', user=no_priv)
117+ >>> cve_2014 in b.cves
118+ True
119+ >>> b.unlinkCVE(cve_2014, user=no_priv)
120+
121 == CVE Reports ==
122
123 Launchpad offers distributions, distribution releases and products with
124
125=== modified file 'lib/lp/bugs/model/cve.py'
126--- lib/lp/bugs/model/cve.py 2013-07-11 06:12:20 +0000
127+++ lib/lp/bugs/model/cve.py 2014-03-05 02:19:53 +0000
128@@ -8,8 +8,6 @@
129 'CveSet',
130 ]
131
132-import re
133-
134 # SQL imports
135 from sqlobject import (
136 SQLMultipleJoin,
137@@ -22,7 +20,10 @@
138 # Zope
139 from zope.interface import implements
140
141-from lp.app.validators.cve import valid_cve
142+from lp.app.validators.cve import (
143+ CVEREF_PATTERN,
144+ valid_cve,
145+ )
146 from lp.bugs.interfaces.buglink import IBugLinkTarget
147 from lp.bugs.interfaces.cve import (
148 CveStatus,
149@@ -41,9 +42,6 @@
150 from lp.services.database.stormexpr import fti_search
151
152
153-cverefpat = re.compile(r'(CVE|CAN)-((19|20)\d{2}\-\d{4})')
154-
155-
156 class Cve(SQLBase, BugLinkTargetMixin):
157 """A CVE database record."""
158
159@@ -147,7 +145,7 @@
160 """See ICveSet."""
161 # let's look for matching entries
162 cves = set()
163- for match in cverefpat.finditer(text):
164+ for match in CVEREF_PATTERN.finditer(text):
165 # let's get the core CVE data
166 sequence = match.group(2)
167 # see if there is already a matching CVE ref in the db, and if