matcher: fix segfault with subscript on non-array element
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 3 Feb 2016 17:32:55 +0000 (18:32 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 3 Feb 2016 17:32:55 +0000 (18:32 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
matcher.c

index ceb756e66573679840f4900dbc2ac7a064afa157..e657395c212de67aab9f8031ee15c978ffa057d7 100644 (file)
--- 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;