##// END OF EJS Templates
subrepo: disallow symlink traversal across subrepo mount point (SEC)...
Yuya Nishihara -
r34985:071cbeba stable
parent child Browse files
Show More
@@ -359,6 +359,12 b' def _sanitize(ui, vfs, ignore):'
359 "in '%s'\n") % vfs.join(dirname))
359 "in '%s'\n") % vfs.join(dirname))
360 vfs.unlink(vfs.reljoin(dirname, f))
360 vfs.unlink(vfs.reljoin(dirname, f))
361
361
362 def _auditsubrepopath(repo, path):
363 # auditor doesn't check if the path itself is a symlink
364 pathutil.pathauditor(repo.root)(path)
365 if repo.wvfs.islink(path):
366 raise error.Abort(_("subrepo '%s' traverses symbolic link") % path)
367
362 def subrepo(ctx, path, allowwdir=False, allowcreate=True):
368 def subrepo(ctx, path, allowwdir=False, allowcreate=True):
363 """return instance of the right subrepo class for subrepo in path"""
369 """return instance of the right subrepo class for subrepo in path"""
364 # subrepo inherently violates our import layering rules
370 # subrepo inherently violates our import layering rules
@@ -369,7 +375,7 b' def subrepo(ctx, path, allowwdir=False, '
369 from . import hg as h
375 from . import hg as h
370 hg = h
376 hg = h
371
377
372 pathutil.pathauditor(ctx.repo().root)(path)
378 _auditsubrepopath(ctx.repo(), path)
373 state = ctx.substate[path]
379 state = ctx.substate[path]
374 if state[2] not in types:
380 if state[2] not in types:
375 raise error.Abort(_('unknown subrepo type %s') % state[2])
381 raise error.Abort(_('unknown subrepo type %s') % state[2])
@@ -387,7 +393,7 b' def nullsubrepo(ctx, path, pctx):'
387 from . import hg as h
393 from . import hg as h
388 hg = h
394 hg = h
389
395
390 pathutil.pathauditor(ctx.repo().root)(path)
396 _auditsubrepopath(ctx.repo(), path)
391 state = ctx.substate[path]
397 state = ctx.substate[path]
392 if state[2] not in types:
398 if state[2] not in types:
393 raise error.Abort(_('unknown subrepo type %s') % state[2])
399 raise error.Abort(_('unknown subrepo type %s') % state[2])
@@ -50,17 +50,35 b' on commit:'
50 $ hg ci -qAm 'add symlink "out"'
50 $ hg ci -qAm 'add symlink "out"'
51 $ hg init ../out
51 $ hg init ../out
52 $ echo 'out = out' >> .hgsub
52 $ echo 'out = out' >> .hgsub
53 BROKEN: should fail
54 $ hg ci -qAm 'add subrepo "out"'
53 $ hg ci -qAm 'add subrepo "out"'
54 abort: subrepo 'out' traverses symbolic link
55 [255]
56
57 prepare tampered repo (including the commit above):
58
59 $ hg import --bypass -qm 'add subrepo "out"' - <<'EOF'
60 > diff --git a/.hgsub b/.hgsub
61 > new file mode 100644
62 > --- /dev/null
63 > +++ b/.hgsub
64 > @@ -0,0 +1,1 @@
65 > +out = out
66 > diff --git a/.hgsubstate b/.hgsubstate
67 > new file mode 100644
68 > --- /dev/null
69 > +++ b/.hgsubstate
70 > @@ -0,0 +1,1 @@
71 > +0000000000000000000000000000000000000000 out
72 > EOF
55 $ cd ../..
73 $ cd ../..
56
74
57 on clone (and update):
75 on clone (and update):
58
76
59 $ mkdir hgsymdir2
77 $ mkdir hgsymdir2
60 BROKEN: should fail to update
61 $ hg clone -q hgsymdir/root hgsymdir2/root
78 $ hg clone -q hgsymdir/root hgsymdir2/root
79 abort: subrepo 'out' traverses symbolic link
80 [255]
62 $ ls hgsymdir2
81 $ ls hgsymdir2
63 out
64 root
82 root
65
83
66 #endif
84 #endif
@@ -400,11 +400,13 b" Don't crash if the subrepo is missing"
400 Don't crash if subrepo is a broken symlink
400 Don't crash if subrepo is a broken symlink
401 $ ln -s broken s
401 $ ln -s broken s
402 $ hg status -S
402 $ hg status -S
403 abort: subrepo 's' traverses symbolic link
404 [255]
403 $ hg push -q
405 $ hg push -q
404 abort: subrepo s is missing (in subrepository "s")
406 abort: subrepo 's' traverses symbolic link
405 [255]
407 [255]
406 $ hg commit --subrepos -qm missing
408 $ hg commit --subrepos -qm missing
407 abort: subrepo s is missing (in subrepository "s")
409 abort: subrepo 's' traverses symbolic link
408 [255]
410 [255]
409 $ rm s
411 $ rm s
410 #endif
412 #endif
General Comments 0
You need to be logged in to leave comments. Login now