# HG changeset patch # User Thomas Arendsen Hein # Date 1142776438 -3600 # Node ID df8416346bb76a9154c24a28bfd13af2aa12fcbd # Parent 6e1a8ea5d7172c7b3105784027f6d3cfafedab40 Enable path validation for copy, rename, debugwalk and other canonpath users. This fixed the last bit of issue134. Added some tests to test-rename and test-walk. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -185,7 +185,9 @@ def canonpath(root, cwd, myname): name = os.path.join(root, cwd, name) name = os.path.normpath(name) if name.startswith(rootsep): - return pconvert(name[len(rootsep):]) + name = name[len(rootsep):] + audit_path(name) + return pconvert(name) elif name == root: return '' else: diff --git a/tests/test-rename b/tests/test-rename --- a/tests/test-rename +++ b/tests/test-rename @@ -179,3 +179,33 @@ hg rename d1/bb d1/b hg status hg debugstate | grep copy hg update -C + +echo "# check illegal path components" + +hg rename d1/d11/a1 .hg/foo +hg status +hg rename d1/d11/a1 ../foo +hg status + +mv d1/d11/a1 .hg/foo +hg rename --after d1/d11/a1 .hg/foo +hg status +hg update -C +rm .hg/foo + +hg rename d1/d11/a1 .hg +hg status +hg rename d1/d11/a1 .. +hg status + +mv d1/d11/a1 .hg +hg rename --after d1/d11/a1 .hg +hg status +hg update -C +rm .hg/a1 + +(cd d1/d11; hg rename ../../d2/b ../../.hg/foo) +hg status +(cd d1/d11; hg rename ../../d2/b ../../../foo) +hg status + diff --git a/tests/test-rename.out b/tests/test-rename.out --- a/tests/test-rename.out +++ b/tests/test-rename.out @@ -254,3 +254,19 @@ A d1/bc R d1/b # idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b) M d1/b +# check illegal path components +abort: path contains illegal component: .hg/foo + +abort: ../foo not under root +abort: path contains illegal component: .hg/foo + +! d1/d11/a1 +abort: path contains illegal component: .hg/a1 + +abort: ../a1 not under root +abort: path contains illegal component: .hg/a1 + +! d1/d11/a1 +abort: path contains illegal component: .hg/foo + +abort: ../../../foo not under root diff --git a/tests/test-walk b/tests/test-walk --- a/tests/test-walk +++ b/tests/test-walk @@ -28,6 +28,8 @@ hg debugwalk .. cd .. hg debugwalk ../beans hg debugwalk . +hg debugwalk .hg +hg debugwalk ../.hg cd .. hg debugwalk -Ibeans hg debugwalk 'glob:mammals/../beans/b*' @@ -35,6 +37,10 @@ hg debugwalk '-X*/Procyonidae' mammals hg debugwalk path:mammals hg debugwalk .. hg debugwalk beans/../.. +hg debugwalk .hg +hg debugwalk beans/../.hg +hg debugwalk beans/../.hg/data +hg debugwalk beans/.hg # Don't know how to test absolute paths without always getting a false # error. #hg debugwalk `pwd`/beans diff --git a/tests/test-walk.out b/tests/test-walk.out --- a/tests/test-walk.out +++ b/tests/test-walk.out @@ -50,6 +50,9 @@ f mammals/Procyonidae/cacomistle Procy f mammals/Procyonidae/coatimundi Procyonidae/coatimundi f mammals/Procyonidae/raccoon Procyonidae/raccoon f mammals/skunk skunk +.hg: No such file or directory +abort: path contains illegal component: .hg + f beans/black beans/black f beans/borlotti beans/borlotti f beans/kidney beans/kidney @@ -65,6 +68,13 @@ f mammals/Procyonidae/raccoon mamma f mammals/skunk mammals/skunk abort: .. not under root abort: beans/../.. not under root +abort: path contains illegal component: .hg + +abort: path contains illegal component: .hg + +abort: path contains illegal component: .hg/data + +beans/.hg: No such file or directory f fennel fennel f fenugreek fenugreek f fiddlehead fiddlehead