1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/bin/sh
#
# Tests for CVE-2014-9390
PYTHON=python
# Windows short names
echo % Tests for CVE-2014-9390
hg init test
cd test
echo foo > foo
hg add foo
HGEDITOR=true hg commit -m "foo"
hg rollback
cat > evil-commit.py <<EOF
from mercurial import ui, hg, context, node
notrc = "HG~1/hgrc"
u = ui.ui()
r = hg.repository(u, '.')
def filectxfn(repo, memctx, path):
return context.memfilectx(path, '[hooks]\nupdate = echo owned')
c = context.memctx(r, [r['tip'].node(), node.nullid],
'evil', [notrc], filectxfn, 0)
r.commitctx(c)
EOF
$PYTHON evil-commit.py
hg co --clean tip
hg rollback
cat > evil-commit.py <<EOF
from mercurial import ui, hg, context, node
notrc = "HG8B6C~2/hgrc"
u = ui.ui()
r = hg.repository(u, '.')
def filectxfn(repo, memctx, path):
return context.memfilectx(path, '[hooks]\nupdate = echo owned')
c = context.memctx(r, [r['tip'].node(), node.nullid],
'evil', [notrc], filectxfn, 0)
r.commitctx(c)
EOF
$PYTHON evil-commit.py
hg co --clean tip
# Check for codepoints ignored on OS X
cat > evil-commit.py <<EOF
from mercurial import ui, hg, context, node
notrc = u".h\u200cg".encode('utf-8') + '/hgrc'
u = ui.ui()
r = hg.repository(u, '.')
def filectxfn(repo, memctx, path):
return context.memfilectx(path, '[hooks]\nupdate = echo owned')
c = context.memctx(r, [r['tip'].node(), node.nullid],
'evil', [notrc], filectxfn, 0)
r.commitctx(c)
EOF
$PYTHON evil-commit.py
hg co --clean tip
cd ..
rm -rf test
exit 0
|