diff --git a/NEWS b/NEWS index 7096164a..fbb0872d 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.32 (???): + * Fixed a bug in xbps_pkgpattern_name() where a string with some special + chars would result in a crash (reported by Gottox). + * Do the package removal in two phases: the first phase checks the user has write permission to the entries being removed, if this succeeds then the package removal is performed. diff --git a/lib/util.c b/lib/util.c index 761d8883..4b355540 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008-2013 Juan Romero Pardines. + * Copyright (c) 2008-2014 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -169,6 +169,9 @@ xbps_pkgpattern_name(const char *pkg) return NULL; len = strlen(pkg) - strlen(res) + 1; + if (strlen(pkg) < len-2) + return NULL; + if (pkg[len-2] == '-') len--; diff --git a/tests/xbps/libxbps/util/main.c b/tests/xbps/libxbps/util/main.c index 5a720ebd..2bbf00ab 100644 --- a/tests/xbps/libxbps/util/main.c +++ b/tests/xbps/libxbps/util/main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2013 Juan Romero Pardines. + * Copyright (c) 2012-2014 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,6 +64,7 @@ ATF_TC_BODY(util_test, tc) ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd-[0-9]*"), "systemd"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd"); ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<4_1?"), "systemd"); + ATF_CHECK_EQ(xbps_pkgpattern_name("*nslookup"), NULL); } ATF_TP_ADD_TCS(tp)