summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2016-02-03 18:32:55 +0100
committerJo-Philipp Wich <jow@openwrt.org>2016-02-03 18:32:55 +0100
commit0c5f596da75c58a1fd0999133e18291a680dd040 (patch)
treec9478bb5ecb6c6fefc7b829368e71e60ce4b08cf
parent691f1065ad33b5d53d342e8705a37563d9ebb8b5 (diff)
downloadjsonpath-0c5f596da75c58a1fd0999133e18291a680dd040.tar.gz
matcher: fix segfault with subscript on non-array element
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r--matcher.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/matcher.c b/matcher.c
index ceb756e..e657395 100644
--- a/matcher.c
+++ b/matcher.c
@@ -258,16 +258,19 @@ jp_match_next(struct jp_opcode *ptr,
break;
case T_NUMBER:
- idx = ptr->num;
+ if (json_object_get_type(cur) == json_type_array)
+ {
+ idx = ptr->num;
- if (idx < 0)
- idx += json_object_array_length(cur);
+ if (idx < 0)
+ idx += json_object_array_length(cur);
- if (idx >= 0)
- next = json_object_array_get_idx(cur, idx);
+ if (idx >= 0)
+ next = json_object_array_get_idx(cur, idx);
- if (next)
- return jp_match_next(ptr->sibling, root, next, cb, priv);
+ if (next)
+ return jp_match_next(ptr->sibling, root, next, cb, priv);
+ }
break;