From: Alexandru Ardelean Date: Sat, 24 Apr 2021 14:06:17 +0000 (+0300) Subject: json_pointer: convert index to size_t type X-Git-Tag: json-c-0.17-20230812~10^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=43d311893516aa56ef2935cb335e169d2671669c;p=thirdparty%2Fjson-c.git json_pointer: convert index to size_t type The index cannot be negative when parsing in is_valid_index(), because we don't allow the '-' character in a string before we get to the strtol() function. So, might as well remove the negative check (for idx) in is_valid_index() and convert it to size_t. That may allow for higher values for the index (which can be insane, but some people may want to try it). Signed-off-by: Alexandru Ardelean --- diff --git a/json_pointer.c b/json_pointer.c index 5abccdb9..15f50261 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -44,7 +44,6 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur, static int is_valid_index(struct json_object *jo, const char *path, size_t *idx) { size_t i, len = strlen(path); - long int idx_val = -1; /* this code-path optimizes a bit, for when we reference the 0-9 index range * in a JSON array and because leading zeros not allowed */ @@ -74,14 +73,9 @@ static int is_valid_index(struct json_object *jo, const char *path, size_t *idx) } } - idx_val = strtol(path, NULL, 10); - if (idx_val < 0) - { - errno = EINVAL; - return 0; - } - *idx = idx_val; - + // We know it's all digits, so the only error case here is overflow, + // but ULLONG_MAX will be longer than any array length so that's ok. + *idx = strtoull(path, NULL, 10); check_oob: len = json_object_array_length(jo); if (*idx >= len)