From f354d19660ce40506eac504b91b153a631b505c2 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Thu, 5 Nov 2020 13:45:37 +0100 Subject: bugs.py: add some checks for package notes --- lib/python/bugs.py | 58 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/python/bugs.py b/lib/python/bugs.py index 7b995c2423..e09a2db55b 100644 --- a/lib/python/bugs.py +++ b/lib/python/bugs.py @@ -557,20 +557,23 @@ class FileBase(debian_support.PackageFile): if handle_xref(self.re_xref_required, self.re_xref, self.re_xref_entry, xref): continue - + + def addPackageNote(note): + self.checkPackageNote(pkg_notes, note, lineno) + pkg_notes.append(note) + if self.re_package_required.match(r): match = self.re_package_version.match(r) if match: (release, p, v, d) = match.groups() - pkg_notes.append( - PackageNoteParsed(p, v, d, release=release)) + addPackageNote(PackageNoteParsed(p, v, d, release=release)) continue match = self.re_package_no_version.match(r) if match: (release, p, v, d) = match.groups() if v == 'not-affected': - pkg_notes.append(PackageNoteParsed + addPackageNote(PackageNoteParsed (p, '0', 'unimportant', release=release)) if d: @@ -581,7 +584,7 @@ class FileBase(debian_support.PackageFile): r = r[:-1] comments.append(('NOTE', r)) elif v == 'end-of-life': - pkg_notes.append(PackageNoteParsed + addPackageNote(PackageNoteParsed (p, None, 'end-of-life', release=release)) if d: @@ -604,7 +607,7 @@ class FileBase(debian_support.PackageFile): reason = v else: reason = None - pkg_notes.append(PackageNoteNoDSA( + addPackageNote(PackageNoteNoDSA( release=release, package=p, comment=d, @@ -623,16 +626,16 @@ class FileBase(debian_support.PackageFile): self.raiseSyntaxError( "ITP note needs Debian bug reference", lineno) - pkg_notes.append(x) + addPackageNote(x) elif v == 'unfixed': - pkg_notes.append(PackageNoteParsed + addPackageNote(PackageNoteParsed (p, None, d, release=release)) elif v == 'removed': - pkg_notes.append(PackageNoteParsed + addPackageNote(PackageNoteParsed (p, None, d, release=release)) self.removed_packages[p] = True elif v == 'undetermined': - pkg_notes.append(PackageNoteParsed + addPackageNote(PackageNoteParsed (p, 'undetermined', d, release=release)) else: self.raiseSyntaxError( @@ -741,6 +744,22 @@ class FileBase(debian_support.PackageFile): parsed, or adds some additional checking.""" return bug + def checkPackageNote(self, notes, note, lineno): + if not notes: + return + + prev_note = notes[-1] + if prev_note.package != note.package: + if prev_note.release and prev_note.release == debian_support.internRelease('experimental'): + #self.raiseSyntaxError("experimental release note must come before the package note") + pass + elif note.release and note.release != debian_support.internRelease('experimental'): + self.raiseSyntaxError("release note must follow its package note", lineno) + else: + if prev_note.release and note.release and prev_note.release < note.release: + self.raiseSyntaxError("release notes not ordered properly", lineno) + + class CVEFile(FileBase): """A CVE file, as used by the Debian testing security team.""" @@ -777,6 +796,14 @@ class CVEFile(FileBase): bug.mergeNotes() return bug + def checkPackageNote(self, notes, note, lineno): + # dont check old entries for now + if self.lineno >= 100000: + return + + super().checkPackageNote(notes, note, lineno) + + class CVEExtendFile(CVEFile): # This is an extend file. The main CVEFile can have a 'CVE-2018-XXXX' (sic) # identifier, which will get converted to TEMP-* automatically. However to @@ -795,6 +822,10 @@ class CVEExtendFile(CVEFile): return CVEFile.isUniqueName(self, name) + def checkPackageNote(self, notes, note, lineno): + pass + + class DSAFile(FileBase): """A DSA file. @@ -840,6 +871,9 @@ class DSAFile(FileBase): bug.mergeNotes() return bug + def checkPackageNote(self, notes, note, lineno): + pass + class DTSAFile(FileBase): """A DTSA file. @@ -884,6 +918,10 @@ class DTSAFile(FileBase): lineno=bug.source_line) return bug + def checkPackageNote(self, notes, note, lineno): + pass + + def test(): assert internUrgency("high") > internUrgency("medium") -- cgit v1.2.3