From 21cb4a9e513ccb6f376fbcaf67957c4851cbbe32 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jan 2020 22:01:54 +0100 Subject: apt(8): Disable regular expressions and fnmatch This is the first step. Next step will be to add warnings to apt-get and then remove support there as well. --- apt-pkg/cacheset.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'apt-pkg/cacheset.cc') diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index dd55edb4e..f5251eda8 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -125,8 +125,16 @@ bool CacheSetHelper::PackageFromTask(PackageContainerInterface * const pci, pkgC // PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/ bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { static const char * const isregex = ".?+*|[^$"; - if (pattern.find_first_of(isregex) == std::string::npos) - return false; + + if (_config->FindB("APT::Cmd::Pattern-Only", false)) + { + // Only allow explicit regexp pattern. + if (pattern.size() == 0 || (pattern[0] != '^' && pattern[pattern.size() - 1] != '$')) + return false; + } else { + if (pattern.find_first_of(isregex) == std::string::npos) + return false; + } bool const wasEmpty = pci->empty(); if (wasEmpty == true) @@ -181,6 +189,8 @@ 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; if (pattern.find_first_of(isfnmatch) == std::string::npos) return false; -- cgit v1.2.3