Mercurial > public > mercurial-scm > hg-stable
diff mercurial/wireprotoframing.py @ 37476:e9dea82ea1f3
wireproto: convert python literal to object without using unsafe eval()
Follows up cc5a040fe150.
At this point, I don't think we need a real eval(). If we want to support
a set literal, maybe we can vendor ast.literal_eval(), which is relatively
simple function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 08 Apr 2018 11:55:46 +0900 |
parents | d33997123ea5 |
children | 0b7475ea38cf |
line wrap: on
line diff
--- a/mercurial/wireprotoframing.py Sun Apr 08 12:30:59 2018 +0900 +++ b/mercurial/wireprotoframing.py Sun Apr 08 11:55:46 2018 +0900 @@ -180,9 +180,6 @@ def makeframefromhumanstring(s): """Create a frame from a human readable string - DANGER: NOT SAFE TO USE WITH UNTRUSTED INPUT BECAUSE OF POTENTIAL - eval() USAGE. DO NOT USE IN CORE. - Strings have the form: <request-id> <stream-id> <stream-flags> <type> <flags> <payload> @@ -198,7 +195,7 @@ Flags can be delimited by `|` to bitwise OR them together. If the payload begins with ``cbor:``, the following string will be - evaluated as Python code and the resulting object will be fed into + evaluated as Python literal and the resulting object will be fed into a CBOR encoder. Otherwise, the payload is interpreted as a Python byte string literal. """ @@ -229,7 +226,8 @@ finalflags |= int(flag) if payload.startswith(b'cbor:'): - payload = cbor.dumps(stringutil.evalpython(payload[5:]), canonical=True) + payload = cbor.dumps(stringutil.evalpythonliteral(payload[5:]), + canonical=True) else: payload = stringutil.unescapestr(payload)