shakaran

patch apt-pkg using mkostemp storing temporal file name

Aug 21st, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.34 KB | None | 0 0
  1. diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
  2. index dca468c..394bc77 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,20 @@ 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. +      TemporaryFileName = string(name);
  26. +      
  27. +      // The file is created with permissions 0600, that is,
  28. +      // read plus write for owner only.
  29. +      if((iFd = mkostemp(name, fileflags)) == -1)
  30. +      {
  31. +          return FileFdError("Could not create temporary file for %s", FileName.c_str());
  32. +      }
  33. +      free(name);
  34. +   }
  35.     else
  36.        iFd = open(FileName.c_str(), fileflags, Perms);
Advertisement
Add Comment
Please, Sign In to add comment