commit:     63691996a5c2bcebf93c27ee8548c7520f9517d7
Author:     John Helmert III <ajak <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 16 02:26:50 2023 +0000
Commit:     John Helmert III <ajak <AT> gentoo <DOT> org>
CommitDate: Fri Jun 16 02:26:50 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=63691996

lib/portage/glsa: raise GlsaFormatException on invalid range types

Bug: https://bugs.gentoo.org/905660
Signed-off-by: John Helmert III <ajak <AT> gentoo.org>

 NEWS                |  3 +++
 lib/portage/glsa.py | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 6982e1d5f..f3afbc366 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ Bug fixes:
 * Adjust write tests for DISTDIR and PORTAGE_TMPDIR to work with automount
   directories (bug #485100, bug #890812).
 
+* glsa-check: appropriately handle more error cases with invalid GLSAs
+  (bug #905660)
+
 portage-3.0.48.1 (2023-06-06)
 ----------------
 

diff --git a/lib/portage/glsa.py b/lib/portage/glsa.py
index 3b82c0de1..648159ad8 100644
--- a/lib/portage/glsa.py
+++ b/lib/portage/glsa.py
@@ -268,7 +268,13 @@ def makeAtom(pkgname, versionNode):
     @rtype:            String
     @return:   the portage atom
     """
-    op = opMapping[versionNode.getAttribute("range")]
+    rangetype = versionNode.getAttribute("range")
+    if rangetype in opMapping:
+        op = opMapping[rangetype]
+    else:
+        raise GlsaFormatException(
+            _(f"Invalid range found for '{pkgname}': {rangetype}")
+        )
     version = getText(versionNode, format="strip")
     rValue = f"{op}{pkgname}-{version}"
     try:
@@ -292,7 +298,11 @@ def makeVersion(versionNode):
     @rtype:            String
     @return:   the version string
     """
-    op = opMapping[versionNode.getAttribute("range")]
+    rangetype = versionNode.getAttribute("range")
+    if rangetype in opMapping:
+        op = opMapping[rangetype]
+    else:
+        raise GlsaFormatException(_(f"Invalid range found: {rangetype}"))
     version = getText(versionNode, format="strip")
     rValue = f"{op}{version}"
     try:

Reply via email to