shakaran

patch apt-pkg using mkostemp

Aug 21st, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.28 KB | None | 0 0
  1. diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
  2. index dca468c..146e4dc 100644
  3. --- a/apt-pkg/contrib/fileutl.cc
  4. +++ b/apt-pkg/contrib/fileutl.cc
  5. @@ -946,9 +946,6 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co
  6.     if ((Mode & Atomic) == Atomic)
  7.     {
  8.        Flags |= Replace;
  9. -      char *name = strdup((FileName + ".XXXXXX").c_str());
  10. -      TemporaryFileName = string(mktemp(name));
  11. -      free(name);
  12.     }
  13.     else if ((Mode & (Exclusive | Create)) == (Exclusive | Create))
  14.     {
  15. @@ -974,8 +971,18 @@ bool FileFd::Open(string FileName,unsigned int const Mode,APT::Configuration::Co
  16.     else if_FLAGGED_SET(Atomic, O_EXCL);
  17.     #undef if_FLAGGED_SET
  18.  
  19. -   if (TemporaryFileName.empty() == false)
  20. -      iFd = open(TemporaryFileName.c_str(), fileflags, Perms);
  21. +   if ((Mode & Atomic) == Atomic)
  22. +   {
  23. +      char *name = strdup((FileName + ".XXXXXX").c_str());
  24. +      
  25. +      // The file is created with permissions 0600, that is,
  26. +      // read plus write for owner only.
  27. +      if((iFd = mkostemp(name, fileflags)) == -1)
  28. +      {
  29. +          return FileFdError("Could not create temporary file for %s", FileName);
  30. +      }
  31. +      free(name);
  32. +   }
  33.     else
  34.        iFd = open(FileName.c_str(), fileflags, Perms);
Advertisement
Add Comment
Please, Sign In to add comment