changeset 42232:29798c9ba5c9 stable

parser: fix crash by parsing "()" in keyword argument position A tree node can be either None or a tuple because x=("group", None) is reduced to x[1].
author Yuya Nishihara <yuya@tcha.org>
date Fri, 03 May 2019 20:06:03 +0900
parents 724dae82c4bd
children e45c6b153e51
files mercurial/parser.py tests/test-revset.t
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parser.py	Wed May 01 14:27:19 2019 -0400
+++ b/mercurial/parser.py	Fri May 03 20:06:03 2019 +0900
@@ -147,7 +147,8 @@
     arguments are rejected, but missing keyword arguments are just omitted.
     """
     poskeys, varkey, keys, optkey = argspec
-    kwstart = next((i for i, x in enumerate(trees) if x[0] == keyvaluenode),
+    kwstart = next((i for i, x in enumerate(trees)
+                    if x and x[0] == keyvaluenode),
                    len(trees))
     if kwstart < len(poskeys):
         raise error.ParseError(_("%(func)s takes at least %(nargs)d positional "
@@ -171,7 +172,7 @@
     if optkey:
         args[optkey] = util.sortdict()
     for x in trees[kwstart:]:
-        if x[0] != keyvaluenode or x[1][0] != keynode:
+        if not x or x[0] != keyvaluenode or x[1][0] != keynode:
             raise error.ParseError(_("%(func)s got an invalid argument")
                                    % {'func': funcname})
         k = x[1][1]
--- a/tests/test-revset.t	Wed May 01 14:27:19 2019 -0400
+++ b/tests/test-revset.t	Fri May 03 20:06:03 2019 +0900
@@ -472,6 +472,12 @@
   $ log 'extra(unknown=branch)'
   hg: parse error: extra got an unexpected keyword argument 'unknown'
   [255]
+  $ log 'extra((), x)'
+  hg: parse error: first argument to extra must be a string
+  [255]
+  $ log 'extra(label=x, ())'
+  hg: parse error: extra got an invalid argument
+  [255]
 
   $ try 'foo=bar|baz'
   (keyvalue