X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/3d5e93f7cd6bea364ca811c7f64b5e1d4174a4ac..9adb9778d11db138d645e037e092db1fb64b5d4a:/apt-pkg/policy.cc diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index 7947103d5..a1e903178 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,8 @@ using namespace std; // --------------------------------------------------------------------- /* Set the defaults for operation. The default mode with no loaded policy file matches the V0 policy engine. */ -pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(0), PFPriority(0), Cache(Owner) +pkgPolicy::pkgPolicy(pkgCache *Owner) : Pins(nullptr), VerPins(nullptr), + PFPriority(nullptr), Cache(Owner), d(NULL) { if (Owner == 0) return; @@ -99,8 +99,8 @@ bool pkgPolicy::InitDefaults() } // Apply the defaults.. - SPtrArray Fixed = new bool[Cache->HeaderP->PackageFileCount]; - memset(Fixed,0,sizeof(*Fixed)*Cache->HeaderP->PackageFileCount); + std::unique_ptr Fixed(new bool[Cache->HeaderP->PackageFileCount]); + memset(Fixed.get(),0,sizeof(Fixed[0])*Cache->HeaderP->PackageFileCount); StatusOverride = false; for (vector::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I) { @@ -236,15 +236,15 @@ pkgCache::VerIterator pkgPolicy::GetCandidateVerNew(pkgCache::PkgIterator const pkgVersioningSystem *vs = Cache->VS; for (pkgCache::VerIterator ver = Pkg.VersionList(); ver.end() == false; ver++) { - int priority = GetPriority(ver); + int priority = GetPriority(ver, true); - if (priority == 0 || priority <= candPriority) - continue; + if (priority == 0 || priority <= candPriority) + continue; - // TODO: Maybe optimize to not compare versions - if (!cur.end() && priority < 1000 - && (vs->CmpVersion(ver.VerStr(), cur.VerStr()) < 0)) - continue; + // TODO: Maybe optimize to not compare versions + if (!cur.end() && priority < 1000 + && (vs->CmpVersion(ver.VerStr(), cur.VerStr()) < 0)) + continue; candPriority = priority; cand = ver; @@ -367,13 +367,14 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgIterator const &Pkg) return Pins[Pkg->ID].Priority; return 0; } -APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver) +APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver, bool ConsiderFiles) { if (VerPins[Ver->ID].Type != pkgVersionMatch::None) return VerPins[Ver->ID].Priority; + if (!ConsiderFiles) + return 0; - - int priority = INT_MIN; + int priority = std::numeric_limits::min(); for (pkgCache::VerFileIterator file = Ver.FileList(); file.end() == false; file++) { /* If this is the status file, and the current version is not the @@ -382,35 +383,19 @@ APT_PURE signed short pkgPolicy::GetPriority(pkgCache::VerIterator const &Ver) out bogus entries that may be due to config-file states, or other. */ if (file.File().Flagged(pkgCache::Flag::NotSource) && Ver.ParentPkg().CurrentVer() != Ver) { - if (priority < 0) - priority = 0; + // Ignore } else if (GetPriority(file.File()) > priority) { priority = GetPriority(file.File()); } } - return priority == INT_MIN ? 0 : priority; + return priority == std::numeric_limits::min() ? 0 : priority; } APT_PURE signed short pkgPolicy::GetPriority(pkgCache::PkgFileIterator const &File) { return PFPriority[File->ID]; } /*}}}*/ -// PreferenceSection class - Overriding the default TrimRecord method /*{{{*/ -// --------------------------------------------------------------------- -/* The preference file is a user generated file so the parser should - therefore be a bit more friendly by allowing comments and new lines - all over the place rather than forcing a special format */ -class PreferenceSection : public pkgTagSection -{ - void TrimRecord(bool /*BeforeRecord*/, const char* &End) - { - for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r' || Stop[0] == '#'); Stop++) - if (Stop[0] == '#') - Stop = (const char*) memchr(Stop,'\n',End-Stop); - } -}; - /*}}}*/ // ReadPinDir - Load the pin files from this dir into a Policy /*{{{*/ // --------------------------------------------------------------------- /* This will load each pin file in the given dir into a Policy. If the @@ -455,8 +440,8 @@ bool ReadPinFile(pkgPolicy &Plcy,string File) pkgTagFile TF(&Fd); if (_error->PendingError() == true) return false; - - PreferenceSection Tags; + + pkgUserTagSection Tags; while (TF.Step(Tags) == true) { // can happen when there are only comments in a record @@ -492,11 +477,18 @@ bool ReadPinFile(pkgPolicy &Plcy,string File) } for (; Word != End && isspace(*Word) != 0; Word++); - short int priority = Tags.FindI("Pin-Priority", 0); + int priority = Tags.FindI("Pin-Priority", 0); + if (priority < std::numeric_limits::min() || + priority > std::numeric_limits::max() || + _error->PendingError()) { + return _error->Error(_("%s: Value %s is outside the range of valid pin priorities (%d to %d)"), + File.c_str(), Tags.FindS("Pin-Priority").c_str(), + std::numeric_limits::min(), + std::numeric_limits::max()); + } if (priority == 0) { - _error->Warning(_("No priority (or zero) specified for pin")); - continue; + return _error->Error(_("No priority (or zero) specified for pin")); } istringstream s(Name);