Fix #68 (xbps_binpkg_arch() asserts if arch contains a dash)
This commit is contained in:
parent
c549252223
commit
b2bc7af66e
3
NEWS
3
NEWS
@ -1,5 +1,8 @@
|
|||||||
xbps-0.42 (???):
|
xbps-0.42 (???):
|
||||||
|
|
||||||
|
* Fixed issue #68 "xbps_binpkg_arch() asserts if arch contains a dash"
|
||||||
|
https://github.com/voidlinux/xbps/issues/68
|
||||||
|
|
||||||
* xbps-query(8): added --cat=FILE mode to print FILE stored in a binary package
|
* xbps-query(8): added --cat=FILE mode to print FILE stored in a binary package
|
||||||
to stdout. This works exactly as the --files mode: if the matching binary package
|
to stdout. This works exactly as the --files mode: if the matching binary package
|
||||||
is not available in the cachedir, xbps will establish a network connection
|
is not available in the cachedir, xbps will establish a network connection
|
||||||
|
84
lib/util.c
84
lib/util.c
@ -107,9 +107,8 @@ char *
|
|||||||
xbps_binpkg_pkgver(const char *pkg)
|
xbps_binpkg_pkgver(const char *pkg)
|
||||||
{
|
{
|
||||||
const char *fname;
|
const char *fname;
|
||||||
char *p, *res;
|
char *p, *p1;
|
||||||
unsigned int i, idx = 0;
|
unsigned int len;
|
||||||
bool valid = false;
|
|
||||||
|
|
||||||
/* skip path if found, only interested in filename */
|
/* skip path if found, only interested in filename */
|
||||||
if ((fname = strrchr(pkg, '/')))
|
if ((fname = strrchr(pkg, '/')))
|
||||||
@ -117,60 +116,30 @@ xbps_binpkg_pkgver(const char *pkg)
|
|||||||
else
|
else
|
||||||
fname = pkg;
|
fname = pkg;
|
||||||
|
|
||||||
/* get the version component first */
|
/* 5 == .xbps */
|
||||||
if ((p = strrchr(fname, '-')) == NULL)
|
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';
|
||||||
|
|
||||||
|
/* sanity check it's a proper pkgver string */
|
||||||
|
if (xbps_pkg_version(p) == NULL) {
|
||||||
|
free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < strlen(p); i++) {
|
|
||||||
if (p[i] == '_')
|
|
||||||
break;
|
|
||||||
if (isdigit((unsigned char)p[i]) && strchr(p, '_')) {
|
|
||||||
valid = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
return p;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xbps_binpkg_arch(const char *pkg)
|
xbps_binpkg_arch(const char *pkg)
|
||||||
{
|
{
|
||||||
const char *p, *fname;
|
const char *fname;
|
||||||
char *pkgver, *res;
|
char *p;
|
||||||
|
unsigned int len;
|
||||||
if ((pkgver = xbps_binpkg_pkgver(pkg)) == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* skip path if found, only interested in filename */
|
/* skip path if found, only interested in filename */
|
||||||
if ((fname = strrchr(pkg, '/')))
|
if ((fname = strrchr(pkg, '/')))
|
||||||
@ -178,17 +147,14 @@ xbps_binpkg_arch(const char *pkg)
|
|||||||
else
|
else
|
||||||
fname = pkg;
|
fname = pkg;
|
||||||
|
|
||||||
p = fname + strlen(pkgver);
|
/* 5 == .xbps */
|
||||||
|
len = strlen(fname) - 5;
|
||||||
|
p = malloc(len+1);
|
||||||
assert(p);
|
assert(p);
|
||||||
if (*p == '.')
|
(void)memcpy(p, fname, len);
|
||||||
p++;
|
p[len] = '\0';
|
||||||
|
|
||||||
res = strdup(p);
|
return strrchr(p, '.') + 1;
|
||||||
assert(res);
|
|
||||||
free(pkgver);
|
|
||||||
res[strlen(res)-5] = '\0';
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -65,6 +65,16 @@ ATF_TC_BODY(util_test, tc)
|
|||||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd");
|
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd");
|
||||||
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<4_1?"), "systemd");
|
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<4_1?"), "systemd");
|
||||||
ATF_CHECK_EQ(xbps_pkgpattern_name("*nslookup"), NULL);
|
ATF_CHECK_EQ(xbps_pkgpattern_name("*nslookup"), NULL);
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64.xbps"), "x86_64");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64.xbps"), "x86_64");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64.xbps"), "foo-1.0_1");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64.xbps"), "foo-1.0_1");
|
||||||
|
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1");
|
||||||
|
ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64.xbps"), NULL);
|
||||||
|
ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64"), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ATF_TP_ADD_TCS(tp)
|
ATF_TP_ADD_TCS(tp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user