commit:     b5c27098e7ead9e86055e2189a2ba7ff5ada7475
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  1 12:32:27 2026 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jan  1 12:32:27 2026 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b5c27098

libq/atom: do stricter check for build_id in atom_explode_cat

something like app-alternatives/bc-1 is not a package with build_id = 1,
so check the trailing -[number] really is trailing, or so far as we can

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index e32d365..b80610d 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2025 Gentoo Foundation
+ * Copyright 2005-2026 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd        - <[email protected]>
@@ -130,15 +130,24 @@ atom_explode_cat(const char *atom, const char *cat)
                        /* probe for the build-id, it should be a number, but 
it can
                         * be optional, which is making it difficult because
                         * in something like PN-VER.gpkg.tar, VER should not be 
seen
-                        * as BUILDID, while a PN can also contain dashes */
+                        * as BUILDID, while a PN can also contain dashes
+                        * see below note on PMS 3.2, we do a loose check on 
-[0-9]
+                        * from the start */
                        while (--ptr > ret->CATEGORY &&
                                   isdigit(*ptr))
                                valid = true;
                        if (valid &&
                                *ptr == '-')
                        {
-                               ret->BUILDID = atoll(&ptr[1]);
-                               *ptr = '\0';
+                               pv = ret->CATEGORY;
+                               while ((pv = strchr(pv, '-')) != NULL) {
+                                       if (isdigit(pv[1]))
+                                               break;
+                               }
+                               if (pv != ptr) {
+                                       ret->BUILDID = atoll(&ptr[1]);
+                                       *ptr = '\0';
+                               }
                        }
                }
        }

Reply via email to