From b4c8d83eabae7bda250b0621d66a03d54b531c4a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 7 Jun 2017 14:07:45 -0400 Subject: [PATCH] lib: json: fix arr_parse() This function currently fails when decoding an array with number of elements exactly equal to the maximum available in the struct. To fix this, move the check for if the current field is past the end of the array to just before attempting to decode a value. This allows the last element to be followed by a JSON_TOK_LIST_END token in the case that the array is full, and the function to return success. Signed-off-by: Marti Bolivar --- lib/json/json.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/json/json.c b/lib/json/json.c index 683bf533c1..ece7773854 100644 --- a/lib/json/json.c +++ b/lib/json/json.c @@ -518,16 +518,16 @@ static int arr_parse(struct json_obj *obj, return 0; } + if (field == last_elem) { + return -ENOSPC; + } + if (decode_value(obj, elem_descr, &value, field, val) < 0) { return -EINVAL; } (*elements)++; - field = (char *)field + elem_size; - if (field == last_elem) { - return -ENOSPC; - } } return -EINVAL;