From 544ccf644288132f805260c4eb9fd12029c5cf8c Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sun, 4 Oct 2015 13:28:16 -0400 Subject: Disallow invalid path elements in jsonb_set Null path elements and, where the object is an array, invalid integer elements now cause an error. Incorrect behaviour noted by Thom Brown, patch from Dmitry Dolgov. Backpatch to 9.5 where jsonb_set was introduced --- src/backend/utils/adt/jsonfuncs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/jsonfuncs.c') diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 154a8837e17..01b6bb0a483 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -3724,6 +3724,9 @@ setPath(JsonbIterator **it, Datum *path_elems, JsonbValue *res = NULL; int r; + if (path_nulls[level]) + elog(ERROR, "path element at the position %d is NULL", level + 1); + r = JsonbIteratorNext(it, &v, false); switch (r) @@ -3875,7 +3878,7 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, lindex = strtol(c, &badp, 10); if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX || lindex < INT_MIN) - idx = nelems; + elog(ERROR, "path element at the position %d is not an integer", level + 1); else idx = lindex; } -- cgit v1.2.3