Commits

Matt Mackall  committed 76b73ce

vfs: use fchmod for _fixfilemode

On general principle, we should use fchmod instead of chmod to avoid
security pitfalls, although none is likely possible here.

  • Participants
  • Parent commits 4871c1f

Comments (0)

Files changed (1)

File mercurial/scmutil.py

     def _cansymlink(self):
         return util.checklink(self.base)
 
-    def _fixfilemode(self, name):
+    def _fixfilemode(self, fp):
         if self.createmode is None:
             return
-        os.chmod(name, self.createmode & 0666)
+        os.fchmod(fp.fileno(), self.createmode & 0666)
 
     def __call__(self, path, mode="r", text=False, atomictemp=False):
         if self._audit:
                     util.rename(util.mktempcopy(f), f)
         fp = util.posixfile(f, mode)
         if nlink == 0:
-            self._fixfilemode(f)
+            self._fixfilemode(fp)
         return fp
 
     def symlink(self, src, dst):
         else:
             f = self(dst, "w")
             f.write(src)
+            self._fixfilemode(f)
             f.close()
-            self._fixfilemode(dst)
 
     def audit(self, path):
         self.auditor(path)