From 0c5f596da75c58a1fd0999133e18291a680dd040 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 3 Feb 2016 18:32:55 +0100 Subject: [PATCH] matcher: fix segfault with subscript on non-array element Signed-off-by: Jo-Philipp Wich --- matcher.c | 17 ++++++++++------- 1 file 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; -- 2.11.0