Patchwork [1,of,5,V2] chgserver: use basename for socket symlink

login
register
mail settings
Submitter Jun Wu
Date March 4, 2016, 1:28 p.m.
Message ID <8868538a8a0d5ca8f36f.1457098134@x1c>
Download mbox | patch
Permalink /patch/13594/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 4, 2016, 1:28 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1457097482 0
#      Fri Mar 04 13:18:02 2016 +0000
# Node ID 8868538a8a0d5ca8f36f0bdea8d11192ff4e8ca0
# Parent  e00e57d836535aadcb13337613d2f891492d8e04
chgserver: use basename for socket symlink

Previously we use full path and the symlink may point to outside (unsafe)
world if the directory is moved. This patch fixes it by only linking to
basename of the target. Therefore the symbolic link and socket files will
always stay in the same directory.
Yuya Nishihara - March 5, 2016, 9:43 a.m.
On Fri, 4 Mar 2016 13:28:54 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1457097482 0
> #      Fri Mar 04 13:18:02 2016 +0000
> # Node ID 8868538a8a0d5ca8f36f0bdea8d11192ff4e8ca0
> # Parent  e00e57d836535aadcb13337613d2f891492d8e04
> chgserver: use basename for socket symlink
> 
> Previously we use full path and the symlink may point to outside (unsafe)
> world if the directory is moved. This patch fixes it by only linking to
> basename of the target. Therefore the symbolic link and socket files will
> always stay in the same directory.

Queued this one. Thanks for the detailed explanation.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -613,7 +613,7 @@ 
         if self.baseaddress == self.address:
             return
         tempaddress = _tempaddress(self.baseaddress)
-        os.symlink(self.address, tempaddress)
+        os.symlink(os.path.basename(self.address), tempaddress)
         util.rename(tempaddress, self.baseaddress)
 
     def _reloadconfig(self, signum, frame):