diff options
-rw-r--r-- | apt-pkg/cacheset.cc | 7 | ||||
-rwxr-xr-x | test/integration/test-apt-patterns | 34 |
2 files changed, 39 insertions, 2 deletions
diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 288180f16..3967ba980 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -189,8 +189,11 @@ bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { static const char * const isfnmatch = ".?*[]!"; - if (_config->FindB("APT::Cmd::Pattern-Only", false)) - return false; + // Whitelist approach: Anything not in here is not a valid pattern + static const char *const isfnmatch_strict = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.:*"; + + if (_config->FindB("APT::Cmd::Pattern-Only", false) && pattern.find_first_not_of(isfnmatch_strict) != std::string::npos) + return false; if (pattern.find_first_of(isfnmatch) == std::string::npos) return false; diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index b55caf35b..b091c8729 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -233,3 +233,37 @@ testsuccessequal "Listing..." apt list '?x-name-fnmatch(1)' testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] manual1/now 1.0 i386 [installed,local]" apt list '?x-name-fnmatch(*1)' + + +# * wildcards should still work +testsuccessequal "Listing... +automatic1/now 1.0 i386 [installed,local] +automatic2/now 1.0 i386 [installed,local]" apt list 'automatic*' + +testfailureequal "Reading package lists... +Building dependency tree... +Reading state information... +Note, selecting 'automatic1' for glob 'automatic*' +Note, selecting 'automatic2' for glob 'automatic*' +automatic1 is already the newest version (1.0). +automatic1 set to manually installed. +automatic2 is already the newest version (1.0). +automatic2 set to manually installed. +You might want to run 'apt --fix-broken install' to correct these. +The following packages have unmet dependencies: + broken : Depends: does-not-exist but it is not installable +E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution)." apt install -s 'automatic*' + +# other wildcards should fail + +# FIXME: This should fail +testsuccessequal "Listing... +automatic1/now 1.0 i386 [installed,local] +automatic2/now 1.0 i386 [installed,local]" apt list 'automatic?' + + + +testfailureequal "Reading package lists... +Building dependency tree... +Reading state information... +E: Unable to locate package automatic?" apt install -s 'automatic?' |