Fix #68 (xbps_binpkg_arch() asserts if arch contains a dash)
This commit is contained in:
84
lib/util.c
84
lib/util.c
@ -107,9 +107,8 @@ char *
|
||||
xbps_binpkg_pkgver(const char *pkg)
|
||||
{
|
||||
const char *fname;
|
||||
char *p, *res;
|
||||
unsigned int i, idx = 0;
|
||||
bool valid = false;
|
||||
char *p, *p1;
|
||||
unsigned int len;
|
||||
|
||||
/* skip path if found, only interested in filename */
|
||||
if ((fname = strrchr(pkg, '/')))
|
||||
@ -117,60 +116,30 @@ xbps_binpkg_pkgver(const char *pkg)
|
||||
else
|
||||
fname = pkg;
|
||||
|
||||
/* get the version component first */
|
||||
if ((p = strrchr(fname, '-')) == NULL)
|
||||
return NULL;
|
||||
/* 5 == .xbps */
|
||||
len = strlen(fname) - 5;
|
||||
p = malloc(len+1);
|
||||
assert(p);
|
||||
(void)memcpy(p, fname, len);
|
||||
p[len] = '\0';
|
||||
p1 = strrchr(p, '.');
|
||||
assert(p1);
|
||||
p[strlen(p)-strlen(p1)] = '\0';
|
||||
|
||||
for (i = 0; i < strlen(p); i++) {
|
||||
if (p[i] == '_')
|
||||
break;
|
||||
if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
/* sanity check it's a proper pkgver string */
|
||||
if (xbps_pkg_version(p) == NULL) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
if (!valid)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* find the index until the architecture component:
|
||||
* this assumes that revision contains 1 or 2 digits!
|
||||
*/
|
||||
for (i = 0; i < strlen(fname); i++) {
|
||||
/* revision with 1 digit: _[digit]. */
|
||||
if (fname[i] == '_' &&
|
||||
isdigit((unsigned char)fname[i+1]) &&
|
||||
fname[i+2] == '.') {
|
||||
idx = i+2;
|
||||
break;
|
||||
}
|
||||
/* revision with 2 digits: _[digit][digit]. */
|
||||
if (fname[i] == '_' &&
|
||||
isdigit((unsigned char)fname[i+1]) &&
|
||||
isdigit((unsigned char)fname[i+2]) &&
|
||||
fname[i+3] == '.') {
|
||||
idx = i+3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!idx)
|
||||
return NULL;
|
||||
|
||||
res = strdup(fname);
|
||||
assert(res);
|
||||
res[idx] = '\0';
|
||||
|
||||
return res;
|
||||
return p;
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_binpkg_arch(const char *pkg)
|
||||
{
|
||||
const char *p, *fname;
|
||||
char *pkgver, *res;
|
||||
|
||||
if ((pkgver = xbps_binpkg_pkgver(pkg)) == NULL)
|
||||
return NULL;
|
||||
const char *fname;
|
||||
char *p;
|
||||
unsigned int len;
|
||||
|
||||
/* skip path if found, only interested in filename */
|
||||
if ((fname = strrchr(pkg, '/')))
|
||||
@ -178,17 +147,14 @@ xbps_binpkg_arch(const char *pkg)
|
||||
else
|
||||
fname = pkg;
|
||||
|
||||
p = fname + strlen(pkgver);
|
||||
/* 5 == .xbps */
|
||||
len = strlen(fname) - 5;
|
||||
p = malloc(len+1);
|
||||
assert(p);
|
||||
if (*p == '.')
|
||||
p++;
|
||||
(void)memcpy(p, fname, len);
|
||||
p[len] = '\0';
|
||||
|
||||
res = strdup(p);
|
||||
assert(res);
|
||||
free(pkgver);
|
||||
res[strlen(res)-5] = '\0';
|
||||
|
||||
return res;
|
||||
return strrchr(p, '.') + 1;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
Reference in New Issue
Block a user