From a7d916ac978023fe35dcd8666d7bc913bab3b0a9 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 18 May 2018 18:55:58 +0200 Subject: atom_explode: find the last version-like component We need to keep on searching until we reached the end of the package/version string, since package names may contain things which are valid versions, as long as they don't end with them. Bug: https://bugs.gentoo.org/567336 --- libq/atom_explode.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'libq/atom_explode.c') diff --git a/libq/atom_explode.c b/libq/atom_explode.c index 07d9cec..a4ba569 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -193,27 +193,32 @@ atom_explode(const char *atom) * doesn't validate as version :( */ ptr = ret->PN; - while ((ptr = strchr(ptr, '-')) != NULL) { + { + char *lastpv = NULL; char *pv; - ptr++; - if (!isdigit(*ptr)) - continue; - /* so we should have something like "-2" here, see if this - * checks out as valid version string */ - pv = ptr; - while (*++ptr != '\0') { - if (*ptr != '.' && !isdigit(*ptr)) - break; - } - /* allow for 1 optional suffix letter */ - if (*ptr >= 'a' && *ptr <= 'z') - ret->letter = *ptr++; - if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { - ptr = pv; - break; /* valid */ + while ((ptr = strchr(ptr, '-')) != NULL) { + ptr++; + if (!isdigit(*ptr)) + continue; + + /* so we should have something like "-2" here, see if this + * checks out as valid version string */ + pv = ptr; + while (*++ptr != '\0') { + if (*ptr != '.' && !isdigit(*ptr)) + break; + } + /* allow for 1 optional suffix letter */ + if (*ptr >= 'a' && *ptr <= 'z') + ret->letter = *ptr++; + if (*ptr == '_' || *ptr == '\0' || *ptr == '-') { + lastpv = pv; + continue; /* valid, keep searching */ + } + ret->letter = '\0'; } - ret->letter = '\0'; + ptr = lastpv; } if (ptr == NULL) { -- cgit v1.2.3-65-gdbad