summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/arfile.cc11
-rw-r--r--apt-pkg/contrib/extracttar.cc60
-rw-r--r--apt-pkg/contrib/fileutl.cc45
-rw-r--r--apt-pkg/contrib/srvrec.cc17
4 files changed, 77 insertions, 56 deletions
diff --git a/apt-pkg/contrib/arfile.cc b/apt-pkg/contrib/arfile.cc
index 3fc3afedb..5cb43c690 100644
--- a/apt-pkg/contrib/arfile.cc
+++ b/apt-pkg/contrib/arfile.cc
@@ -92,7 +92,7 @@ bool ARArchive::LoadHeaders()
StrToNum(Head.Size,Memb->Size,sizeof(Head.Size)) == false)
{
delete Memb;
- return _error->Error(_("Invalid archive member header %s"), Head.Name);
+ return _error->Error(_("Invalid archive member header"));
}
// Check for an extra long name string
@@ -119,7 +119,14 @@ bool ARArchive::LoadHeaders()
else
{
unsigned int I = sizeof(Head.Name) - 1;
- for (; Head.Name[I] == ' ' || Head.Name[I] == '/'; I--);
+ for (; Head.Name[I] == ' ' || Head.Name[I] == '/'; I--)
+ {
+ if (I == 0)
+ {
+ delete Memb;
+ return _error->Error(_("Invalid archive member header"));
+ }
+ }
Memb->Name = std::string(Head.Name,I+1);
}
diff --git a/apt-pkg/contrib/extracttar.cc b/apt-pkg/contrib/extracttar.cc
index 9bb0a55c0..1616c9f12 100644
--- a/apt-pkg/contrib/extracttar.cc
+++ b/apt-pkg/contrib/extracttar.cc
@@ -254,53 +254,53 @@ bool ExtractTar::Go(pkgDirStream &Stream)
default:
BadRecord = true;
- _error->Warning(_("Unknown TAR header type %u, member %s"),(unsigned)Tar->LinkFlag,Tar->Name);
+ _error->Warning(_("Unknown TAR header type %u"), (unsigned)Tar->LinkFlag);
break;
}
-
+
int Fd = -1;
- if (BadRecord == false)
- if (Stream.DoItem(Itm,Fd) == false)
+ if (not BadRecord && not Stream.DoItem(Itm, Fd))
+ return false;
+
+ if (Fd == -1 || Fd < -2 || BadRecord)
+ {
+ if (Itm.Size > 0 && not InFd.Skip(((Itm.Size + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block)))
return false;
-
- // Copy the file over the FD
- unsigned long long Size = Itm.Size;
- while (Size != 0)
+ }
+ else if (Itm.Size != 0)
{
+ // Copy the file over the FD
+ auto Size = Itm.Size;
unsigned char Junk[32*1024];
- unsigned long Read = min(Size, (unsigned long long)sizeof(Junk));
- if (InFd.Read(Junk,((Read+511)/512)*512) == false)
- return false;
-
- if (BadRecord == false)
+ do
{
+ auto const Read = std::min<unsigned long long>(Size, sizeof(Junk));
+ if (not InFd.Read(Junk, ((Read + (sizeof(Block) - 1)) / sizeof(Block)) * sizeof(Block)))
+ return false;
+
if (Fd > 0)
{
- if (write(Fd,Junk,Read) != (signed)Read)
- return Stream.Fail(Itm,Fd);
+ if (not FileFd::Write(Fd, Junk, Read))
+ return Stream.Fail(Itm, Fd);
}
- else
+ // An Fd of -2 means to send to a special processing function
+ else if (Fd == -2)
{
- /* An Fd of -2 means to send to a special processing
- function */
- if (Fd == -2)
- if (Stream.Process(Itm,Junk,Read,Itm.Size - Size) == false)
- return Stream.Fail(Itm,Fd);
+ if (not Stream.Process(Itm, Junk, Read, Itm.Size - Size))
+ return Stream.Fail(Itm, Fd);
}
- }
-
- Size -= Read;
+
+ Size -= Read;
+ } while (Size != 0);
}
-
+
// And finish up
- if (BadRecord == false)
- if (Stream.FinishedFile(Itm,Fd) == false)
- return false;
-
+ if (not BadRecord && not Stream.FinishedFile(Itm, Fd))
+ return false;
LastLongName.erase();
LastLongLink.erase();
}
-
+
return Done();
}
/*}}}*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 045dbe17d..e91c1acc3 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -3150,30 +3150,49 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co
}
FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd, bool Buffered)
{
- char fn[512];
- FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd;
-
+ std::string fn;
std::string const tempdir = GetTempDir();
- snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
- tempdir.c_str(), Prefix.c_str());
- int const fd = mkstemp(fn);
+ int fd = -1;
+#ifdef O_TMPFILE
if (ImmediateUnlink)
- unlink(fn);
+ fd = open(tempdir.c_str(), O_RDWR|O_TMPFILE|O_EXCL|O_CLOEXEC, 0600);
if (fd < 0)
+#endif
{
- _error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
- if (TmpFd == nullptr)
- delete Fd;
+ auto const suffix = Prefix.find(".XXXXXX.");
+ std::vector<char> buffer(tempdir.length() + 1 + Prefix.length() + (suffix == std::string::npos ? 7 : 0) + 1, '\0');
+ if (suffix != std::string::npos)
+ {
+ if (snprintf(buffer.data(), buffer.size(), "%s/%s", tempdir.c_str(), Prefix.c_str()) > 0)
+ {
+ ssize_t const suffixlen = (buffer.size() - 1) - (tempdir.length() + 1 + suffix + 7);
+ if (likely(suffixlen > 0))
+ fd = mkstemps(buffer.data(), suffixlen);
+ }
+ }
+ else
+ {
+ if (snprintf(buffer.data(), buffer.size(), "%s/%s.XXXXXX", tempdir.c_str(), Prefix.c_str()) > 0)
+ fd = mkstemp(buffer.data());
+ }
+ fn.assign(buffer.data(), buffer.size() - 1);
+ if (ImmediateUnlink && fd != -1)
+ unlink(fn.c_str());
+ }
+ if (fd < 0)
+ {
+ _error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn.c_str());
return nullptr;
}
- if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite | (Buffered ? FileFd::BufferedWrite : 0), FileFd::None, true))
+ FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd;
+ if (not Fd->OpenDescriptor(fd, FileFd::ReadWrite | (Buffered ? FileFd::BufferedWrite : 0), FileFd::None, true))
{
- _error->Errno("GetTempFile",_("Unable to write to %s"),fn);
+ _error->Errno("GetTempFile",_("Unable to write to %s"),fn.c_str());
if (TmpFd == nullptr)
delete Fd;
return nullptr;
}
- if (ImmediateUnlink == false)
+ if (not ImmediateUnlink)
Fd->SetFileName(fn);
return Fd;
}
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index 7d9bf116e..4ca208273 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/apt-pkg/contrib/srvrec.cc
@@ -137,17 +137,12 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
// sort them by priority
std::stable_sort(Result.begin(), Result.end());
- for(std::vector<SrvRec>::iterator I = Result.begin();
- I != Result.end(); ++I)
- {
- if (_config->FindB("Debug::Acquire::SrvRecs", false) == true)
- {
- std::cerr << "SrvRecs: got " << I->target
- << " prio: " << I->priority
- << " weight: " << I->weight
- << std::endl;
- }
- }
+ if (_config->FindB("Debug::Acquire::SrvRecs", false))
+ for(auto const &R : Result)
+ std::cerr << "SrvRecs: got " << R.target
+ << " prio: " << R.priority
+ << " weight: " << R.weight
+ << '\n';
return true;
}