summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/algorithms.cc24
-rw-r--r--apt-pkg/cacheiterators.h8
-rw-r--r--apt-pkg/contrib/fileutl.cc23
-rw-r--r--apt-pkg/contrib/sptr.h4
-rw-r--r--apt-pkg/depcache.cc6
-rw-r--r--apt-pkg/depcache.h2
-rw-r--r--apt-pkg/orderlist.cc22
-rw-r--r--apt-pkg/packagemanager.cc24
-rw-r--r--apt-pkg/pkgcache.h6
-rw-r--r--apt-pkg/pkgcachegen.cc36
-rw-r--r--apt-pkg/policy.cc22
-rw-r--r--apt-pkg/policy.h2
-rw-r--r--apt-pkg/tagfile.cc9
13 files changed, 103 insertions, 85 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index 747b73e05..446afa08d 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -476,8 +476,8 @@ void pkgProblemResolver::MakeScores()
}
// Copy the scores to advoid additive looping
- SPtrArray<int> OldScores = new int[Size];
- memcpy(OldScores,Scores,sizeof(*Scores)*Size);
+ std::unique_ptr<int[]> OldScores(new int[Size]);
+ memcpy(OldScores.get(),Scores,sizeof(*Scores)*Size);
/* Now we cause 1 level of dependency inheritance, that is we add the
score of the packages that depend on the target Package. This
@@ -702,17 +702,17 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
operates from highest score to lowest. This prevents problems when
high score packages cause the removal of lower score packages that
would cause the removal of even lower score packages. */
- SPtrArray<pkgCache::Package *> PList = new pkgCache::Package *[Size];
- pkgCache::Package **PEnd = PList;
+ std::unique_ptr<pkgCache::Package *[]> PList(new pkgCache::Package *[Size]);
+ pkgCache::Package **PEnd = PList.get();
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
*PEnd++ = I;
This = this;
- qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
+ qsort(PList.get(),PEnd - PList.get(),sizeof(PList[0]),&ScoreSort);
if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
{
clog << "Show Scores" << endl;
- for (pkgCache::Package **K = PList; K != PEnd; K++)
+ for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
if (Scores[(*K)->ID] != 0)
{
pkgCache::PkgIterator Pkg(Cache,*K);
@@ -734,7 +734,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
for (int Counter = 0; Counter != 10 && Change == true; Counter++)
{
Change = false;
- for (pkgCache::Package **K = PList; K != PEnd; K++)
+ for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
{
pkgCache::PkgIterator I(Cache,*K);
@@ -845,8 +845,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
/* Look across the version list. If there are no possible
targets then we keep the package and bail. This is necessary
if a package has a dep on another package that can't be found */
- SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
- if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
+ std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+ if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected &&
Start.IsNegative() == false &&
Cache[I].NowBroken() == false)
{
@@ -863,7 +863,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
}
bool Done = false;
- for (pkgCache::Version **V = VList; *V != 0; V++)
+ for (pkgCache::Version **V = VList.get(); *V != 0; V++)
{
pkgCache::VerIterator Ver(Cache,*V);
pkgCache::PkgIterator Pkg = Ver.ParentPkg();
@@ -1233,8 +1233,8 @@ bool pkgProblemResolver::ResolveByKeepInternal()
clog << "Package " << I.FullName(false) << " " << Start << endl;
// Look at all the possible provides on this package
- SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
- for (pkgCache::Version **V = VList; *V != 0; V++)
+ std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+ for (pkgCache::Version **V = VList.get(); *V != 0; V++)
{
pkgCache::VerIterator Ver(Cache,*V);
pkgCache::PkgIterator Pkg = Ver.ParentPkg();
diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h
index f8321079a..48547e564 100644
--- a/apt-pkg/cacheiterators.h
+++ b/apt-pkg/cacheiterators.h
@@ -157,11 +157,7 @@ class pkgCache::PkgIterator: public Iterator<Package, PkgIterator> {
inline const char *Name() const { return Group().Name(); }
// Versions have sections - and packages can have different versions with different sections
// so this interface is broken by design. Run as fast as you can to Version.Section().
- APT_DEPRECATED inline const char *Section() const {
- APT_IGNORE_DEPRECATED_PUSH
- return S->Section == 0?0:Owner->StrP + S->Section;
- APT_IGNORE_DEPRECATED_POP
- }
+ APT_DEPRECATED inline const char *Section() const;
inline bool Purge() const {return S->CurrentState == pkgCache::State::Purge ||
(S->CurrentVer == 0 && S->CurrentState == pkgCache::State::NotInstalled);}
inline const char *Arch() const {return S->Arch == 0?0:Owner->StrP + S->Arch;}
@@ -518,5 +514,7 @@ inline pkgCache::VerFileIterator pkgCache::VerIterator::FileList() const
{return VerFileIterator(*Owner,Owner->VerFileP + S->FileList);}
inline pkgCache::DescFileIterator pkgCache::DescIterator::FileList() const
{return DescFileIterator(*Owner,Owner->DescFileP + S->FileList);}
+APT_DEPRECATED inline const char * pkgCache::PkgIterator::Section() const
+ {return S->VersionList == 0 ? 0 : VersionList().Section();}
/*}}}*/
#endif
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 4cc8112af..1be782bac 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -52,6 +52,7 @@
#include <set>
#include <algorithm>
+#include <memory>
#ifdef HAVE_ZLIB
#include <zlib.h>
@@ -159,7 +160,7 @@ bool CopyFile(FileFd &From,FileFd &To)
return false;
// Buffered copy between fds
- SPtrArray<unsigned char> Buf = new unsigned char[64000];
+ std::unique_ptr<unsigned char[]> Buf(new unsigned char[64000]);
unsigned long long Size = From.Size();
while (Size != 0)
{
@@ -167,8 +168,8 @@ bool CopyFile(FileFd &From,FileFd &To)
if (Size > 64000)
ToRead = 64000;
- if (From.Read(Buf,ToRead) == false ||
- To.Write(Buf,ToRead) == false)
+ if (From.Read(Buf.get(),ToRead) == false ||
+ To.Write(Buf.get(),ToRead) == false)
return false;
Size -= ToRead;
@@ -2251,22 +2252,32 @@ bool DropPrivileges() /*{{{*/
return _error->Error("No user %s, can not drop rights", toUser.c_str());
// Do not change the order here, it might break things
+ // Get rid of all our supplementary groups first
if (setgroups(1, &pw->pw_gid))
return _error->Errno("setgroups", "Failed to setgroups");
+ // Now change the group ids to the new user
+#ifdef HAVE_SETRESGID
+ if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) != 0)
+ return _error->Errno("setresgid", "Failed to set new group ids");
+#else
if (setegid(pw->pw_gid) != 0)
return _error->Errno("setegid", "Failed to setegid");
if (setgid(pw->pw_gid) != 0)
return _error->Errno("setgid", "Failed to setgid");
+#endif
+ // Change the user ids to the new user
+#ifdef HAVE_SETRESUID
+ if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) != 0)
+ return _error->Errno("setresuid", "Failed to set new user ids");
+#else
if (setuid(pw->pw_uid) != 0)
return _error->Errno("setuid", "Failed to setuid");
-
- // the seteuid() is probably uneeded (at least thats what the linux
- // man-page says about setuid(2)) but we cargo culted it anyway
if (seteuid(pw->pw_uid) != 0)
return _error->Errno("seteuid", "Failed to seteuid");
+#endif
// Verify that the user has only a single group, and the correct one
gid_t groups[1];
diff --git a/apt-pkg/contrib/sptr.h b/apt-pkg/contrib/sptr.h
index e2e811b1d..92f4cdec8 100644
--- a/apt-pkg/contrib/sptr.h
+++ b/apt-pkg/contrib/sptr.h
@@ -22,7 +22,7 @@
#define SMART_POINTER_H
template <class T>
-class SPtr
+class APT_DEPRECATED SPtr
{
public:
T *Ptr;
@@ -43,7 +43,7 @@ class SPtr
};
template <class T>
-class SPtrArray
+class APT_DEPRECATED SPtrArray
{
public:
T *Ptr;
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 02f61bf13..367605826 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -1281,9 +1281,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
Otherwise we remove the offender if needed */
else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
{
- SPtrArray<Version *> List = Start.AllTargets();
+ std::unique_ptr<Version *[]> List(Start.AllTargets());
pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
- for (Version **I = List; *I != 0; I++)
+ for (Version **I = List.get(); *I != 0; I++)
{
VerIterator Ver(*this,*I);
PkgIterator Pkg = Ver.ParentPkg();
@@ -2010,7 +2010,7 @@ bool pkgDepCache::MarkAndSweep(InRootSetFunc &rootFunc)
}
bool pkgDepCache::MarkAndSweep()
{
- std::auto_ptr<InRootSetFunc> f(GetRootSetFunc());
+ std::unique_ptr<InRootSetFunc> f(GetRootSetFunc());
if(f.get() != NULL)
return MarkAndSweep(*f.get());
else
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index aa281f695..6a1d6f8b3 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -250,7 +250,7 @@ class pkgDepCache : protected pkgCache::Namespace
inline bool Keep() const {return Mode == ModeKeep;};
inline bool Protect() const {return (iFlags & Protected) == Protected;};
inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
- inline bool Upgradable() const {return Status >= 1;};
+ inline bool Upgradable() const {return Status >= 1 && CandidateVer != NULL;};
inline bool Downgrade() const {return Status < 0 && Mode == ModeInstall;};
inline bool Held() const {return Status != 0 && Keep();};
inline bool NowBroken() const {return (DepState & DepNowMin) != DepNowMin;};
diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc
index edbdd09ab..dae37e8f8 100644
--- a/apt-pkg/orderlist.cc
+++ b/apt-pkg/orderlist.cc
@@ -142,9 +142,9 @@ bool pkgOrderList::DoRun()
{
// Temp list
unsigned long Size = Cache.Head().PackageCount;
- SPtrArray<Package *> NList = new Package *[Size];
- SPtrArray<Package *> AfterList = new Package *[Size];
- AfterEnd = AfterList;
+ std::unique_ptr<Package *[]> NList(new Package *[Size]);
+ std::unique_ptr<Package *[]> AfterList(new Package *[Size]);
+ AfterEnd = AfterList.get();
Depth = 0;
WipeFlags(Added | AddPending | Loop | InList);
@@ -154,7 +154,7 @@ bool pkgOrderList::DoRun()
// Rebuild the main list into the temp list.
iterator OldEnd = End;
- End = NList;
+ End = NList.get();
for (iterator I = List; I != OldEnd; ++I)
if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false)
{
@@ -163,12 +163,12 @@ bool pkgOrderList::DoRun()
}
// Copy the after list to the end of the main list
- for (Package **I = AfterList; I != AfterEnd; I++)
+ for (Package **I = AfterList.get(); I != AfterEnd; I++)
*End++ = *I;
// Swap the main list to the new list
delete [] List;
- List = NList.UnGuard();
+ List = NList.release();
return true;
}
/*}}}*/
@@ -512,8 +512,8 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver)
against it! */
bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
{
- SPtrArray<Version *> List = D.AllTargets();
- for (Version **I = List; *I != 0; ++I)
+ std::unique_ptr<Version *[]> List(D.AllTargets());
+ for (Version **I = List.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator Pkg = Ver.ParentPkg();
@@ -541,7 +541,7 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
}
if (D.IsNegative() == false)
return true;
- for (Version **I = List; *I != 0; ++I)
+ for (Version **I = List.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator Pkg = Ver.ParentPkg();
@@ -1075,9 +1075,9 @@ void pkgOrderList::WipeFlags(unsigned long F)
this fails to produce a suitable result. */
bool pkgOrderList::CheckDep(DepIterator D)
{
- SPtrArray<Version *> List = D.AllTargets();
+ std::unique_ptr<Version *[]> List(D.AllTargets());
bool Hit = false;
- for (Version **I = List; *I != 0; I++)
+ for (Version **I = List.get(); *I != 0; I++)
{
VerIterator Ver(Cache,*I);
PkgIterator Pkg = Ver.ParentPkg();
diff --git a/apt-pkg/packagemanager.cc b/apt-pkg/packagemanager.cc
index 78142ab13..dcae01126 100644
--- a/apt-pkg/packagemanager.cc
+++ b/apt-pkg/packagemanager.cc
@@ -390,9 +390,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
// to do anything at all
for (DepIterator Cur = Start; true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
- for (Version **I = VList; *I != 0; ++I)
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
@@ -440,9 +440,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
// probably due to loops.
for (DepIterator Cur = Start; true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
- for (Version **I = VList; *I != 0; ++I)
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
@@ -515,9 +515,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
// Search for dependencies which are unpacked but aren't configured yet (maybe loops)
for (DepIterator Cur = Start; true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
- for (Version **I = VList; *I != 0; ++I)
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
@@ -726,8 +726,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
// Look for easy targets: packages that are already okay
for (DepIterator Cur = Start; Bad == true; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *> VList(Cur.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator Pkg = Ver.ParentPkg();
@@ -750,8 +750,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
// Look for something that could be configured.
for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
{
- SPtrArray<Version *> VList = Cur.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *[]> VList(Cur.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator DepPkg = Ver.ParentPkg();
@@ -806,8 +806,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
End->Type == pkgCache::Dep::Obsoletes ||
End->Type == pkgCache::Dep::DpkgBreaks)
{
- SPtrArray<Version *> VList = End.AllTargets();
- for (Version **I = VList; *I != 0; ++I)
+ std::unique_ptr<Version *[]> VList(End.AllTargets());
+ for (Version **I = VList.get(); *I != 0; ++I)
{
VerIterator Ver(Cache,*I);
PkgIterator ConflictPkg = Ver.ParentPkg();
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index e59697c28..ff250b532 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -429,12 +429,6 @@ struct pkgCache::Package
map_pointer_t VersionList; // Version
/** \brief index to the installed version */
map_pointer_t CurrentVer; // Version
- /** \brief indicates nothing (consistently)
- This field used to contain ONE section the package belongs to,
- if those differs between versions it is a RANDOM one.
- The Section() method tries to reproduce it, but the only sane
- thing to do is use the Section field from the version! */
- APT_DEPRECATED map_ptrloc Section; // StringItem
/** \brief index of the group this package belongs to */
map_pointer_t Group; // Group the Package belongs to
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index ef7afda94..68175a24a 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -1250,8 +1250,8 @@ static bool CheckValidity(const string &CacheFile,
// Map it
FileFd CacheF(CacheFile,FileFd::ReadOnly);
- SPtr<MMap> Map = new MMap(CacheF,0);
- pkgCache Cache(Map);
+ std::unique_ptr<MMap> Map(new MMap(CacheF,0));
+ pkgCache Cache(Map.get());
if (_error->PendingError() == true || Map->Size() == 0)
{
if (Debug == true)
@@ -1260,8 +1260,8 @@ static bool CheckValidity(const string &CacheFile,
return false;
}
- SPtrArray<bool> RlsVisited = new bool[Cache.HeaderP->ReleaseFileCount];
- memset(RlsVisited,0,sizeof(*RlsVisited)*Cache.HeaderP->ReleaseFileCount);
+ std::unique_ptr<bool[]> RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]);
+ memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount);
std::vector<pkgIndexFile *> Files;
for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i)
{
@@ -1295,8 +1295,8 @@ static bool CheckValidity(const string &CacheFile,
/* Now we check every index file, see if it is in the cache,
verify the IMS data and check that it is on the disk too.. */
- SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
- memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
+ std::unique_ptr<bool[]> Visited(new bool[Cache.HeaderP->PackageFileCount]);
+ memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount);
for (std::vector<pkgIndexFile *>::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile)
{
if (Debug == true)
@@ -1342,7 +1342,7 @@ static bool CheckValidity(const string &CacheFile,
}
if (OutMap != 0)
- *OutMap = Map.UnGuard();
+ *OutMap = Map.release();
return true;
}
/*}}}*/
@@ -1483,16 +1483,16 @@ static bool writeBackMMapToFile(pkgCacheGenerator * const Gen, DynamicMMap * con
return true;
}
static bool loadBackMMapFromFile(std::unique_ptr<pkgCacheGenerator> &Gen,
- SPtr<DynamicMMap> &Map, OpProgress * const Progress, std::string const &FileName)
+ std::unique_ptr<DynamicMMap> &Map, OpProgress * const Progress, std::string const &FileName)
{
- Map = CreateDynamicMMap(NULL, 0);
+ Map.reset(CreateDynamicMMap(NULL, 0));
FileFd CacheF(FileName, FileFd::ReadOnly);
map_pointer_t const alloc = Map->RawAllocate(CacheF.Size());
if ((alloc == 0 && _error->PendingError())
|| CacheF.Read((unsigned char *)Map->Data() + alloc,
CacheF.Size()) == false)
return false;
- Gen.reset(new pkgCacheGenerator(Map.Get(),Progress));
+ Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
return true;
}
APT_DEPRECATED bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
@@ -1578,7 +1578,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
}
// At this point we know we need to construct something, so get storage ready
- SPtr<DynamicMMap> Map = CreateDynamicMMap(NULL, 0);
+ std::unique_ptr<DynamicMMap> Map(CreateDynamicMMap(NULL, 0));
if (Debug == true)
std::clog << "Open memory Map (not filebased)" << std::endl;
@@ -1599,7 +1599,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
{
if (Debug == true)
std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
- Gen.reset(new pkgCacheGenerator(Map.Get(),Progress));
+ Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
TotalSize += ComputeSize(&List, Files.begin(),Files.end());
if (BuildCache(*Gen, Progress, CurrentSize, TotalSize, &List,
@@ -1607,7 +1607,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
return false;
if (Writeable == true && SrcCacheFile.empty() == false)
- if (writeBackMMapToFile(Gen.get(), Map.Get(), SrcCacheFile) == false)
+ if (writeBackMMapToFile(Gen.get(), Map.get(), SrcCacheFile) == false)
return false;
}
@@ -1620,7 +1620,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
return false;
if (Writeable == true && CacheFile.empty() == false)
- if (writeBackMMapToFile(Gen.get(), Map.Get(), CacheFile) == false)
+ if (writeBackMMapToFile(Gen.get(), Map.get(), CacheFile) == false)
return false;
}
@@ -1644,7 +1644,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
}
if (OutMap != nullptr)
- *OutMap = Map.UnGuard();
+ *OutMap = Map.release();
if (Debug == true)
std::clog << "Everything is ready for shipping" << std::endl;
@@ -1662,7 +1662,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
if (_system->AddStatusFiles(Files) == false)
return false;
- SPtr<DynamicMMap> Map = CreateDynamicMMap(NULL, 0);
+ std::unique_ptr<DynamicMMap> Map(CreateDynamicMMap(NULL, 0));
map_filesize_t CurrentSize = 0;
map_filesize_t TotalSize = 0;
@@ -1671,7 +1671,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
// Build the status cache
if (Progress != NULL)
Progress->OverallProgress(0,1,1,_("Reading package lists"));
- pkgCacheGenerator Gen(Map.Get(),Progress);
+ pkgCacheGenerator Gen(Map.get(),Progress);
if (_error->PendingError() == true)
return false;
if (BuildCache(Gen,Progress,CurrentSize,TotalSize, NULL,
@@ -1680,7 +1680,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
if (_error->PendingError() == true)
return false;
- *OutMap = Map.UnGuard();
+ *OutMap = Map.release();
return true;
}
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index c12d8699b..4711372bc 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -100,8 +100,8 @@ bool pkgPolicy::InitDefaults()
}
// Apply the defaults..
- SPtrArray<bool> Fixed = new bool[Cache->HeaderP->PackageFileCount];
- memset(Fixed,0,sizeof(*Fixed)*Cache->HeaderP->PackageFileCount);
+ std::unique_ptr<bool[]> Fixed(new bool[Cache->HeaderP->PackageFileCount]);
+ memset(Fixed.get(),0,sizeof(Fixed[0])*Cache->HeaderP->PackageFileCount);
StatusOverride = false;
for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I)
{
@@ -368,11 +368,12 @@ 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 = std::numeric_limits<int>::min();
for (pkgCache::VerFileIterator file = Ver.FileList(); file.end() == false; file++)
@@ -477,11 +478,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<short>::min() ||
+ priority > std::numeric_limits<short>::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<short>::min(),
+ std::numeric_limits<short>::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);
diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h
index b3e1ec6b1..5be6657e9 100644
--- a/apt-pkg/policy.h
+++ b/apt-pkg/policy.h
@@ -80,7 +80,7 @@ class pkgPolicy : public pkgDepCache::Policy
// Things for the cache interface.
virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg) APT_OVERRIDE;
- virtual signed short GetPriority(pkgCache::VerIterator const &Pkg);
+ virtual signed short GetPriority(pkgCache::VerIterator const &Pkg, bool ConsiderFiles = true);
virtual signed short GetPriority(pkgCache::PkgFileIterator const &File) APT_OVERRIDE;
bool InitDefaults();
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index 253b1b7a3..8acecd735 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -533,9 +533,16 @@ signed int pkgTagSection::FindI(const char *Tag,signed long Default) const
return Default;
strncpy(S,Start,Stop-Start);
S[Stop - Start] = 0;
-
+
+ errno = 0;
char *End;
signed long Result = strtol(S,&End,10);
+ if (errno == ERANGE)
+ _error->Errno("strtol", _("Cannot convert %s to integer"), S);
+ if (Result < std::numeric_limits<int>::min() || Result > std::numeric_limits<int>::max()) {
+ errno = ERANGE;
+ _error->Errno("", _("Cannot convert %s to integer"), S);
+ }
if (S == End)
return Default;
return Result;