commit:     e5ed806b4a2784ced621efd8c5b036bddef780f8
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 28 16:12:54 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Dec 28 16:12:54 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e5ed806b

atom_explode: be more careful with eating suffix letters

Make sure we don't just eat a char at the end of the atom, because if
that char appears after a -, it will be seen as version part.  An
example is xerces-c, where the parsed atom form would just be xerces.

Bug: https://bugs.gentoo.org/638816

 libq/atom_explode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index 956ac49..057bfa1 100644
--- a/libq/atom_explode.c
+++ b/libq/atom_explode.c
@@ -218,9 +218,12 @@ atom_explode(const char *atom)
                ret->suffixes[idx] = t;
        }
 
-       /* allow for 1 optional suffix letter */
+       /* allow for 1 optional suffix letter, must be following a number
+        * otherwise we eat stuff like -c, see bug #639978 */
        ptr = ret->PN + strlen(ret->PN);
-       if (ptr[-1] >= 'a' && ptr[-1] <= 'z') {
+       if (ptr[-1] >= 'a' && ptr[-1] <= 'z' &&
+                       ptr - 2 > ret->PN && ptr[-2] >= '0' && ptr[-2] <= '9')
+       {
                ret->letter = ptr[-1];
                --ptr;
        }

Reply via email to