summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonfuncs.c
diff options
context:
space:
mode:
authorAndrew Dunstan2015-10-04 17:28:16 +0000
committerAndrew Dunstan2015-10-04 17:28:16 +0000
commit1edd4ec831458e10b524d1473a7de5791aa8753e (patch)
tree1b2f229c94932b0b92421e1b258b44f4f802cddf /src/backend/utils/adt/jsonfuncs.c
parent6390c8c654d07c08686adbbc595a13d76b573653 (diff)
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
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r--src/backend/utils/adt/jsonfuncs.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 154a8837e1..01b6bb0a48 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;
}