aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonfuncs.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2015-10-04 13:28:16 -0400
committerAndrew Dunstan <andrew@dunslane.net>2015-10-04 13:48:24 -0400
commit544ccf644288132f805260c4eb9fd12029c5cf8c (patch)
tree7dd30ce4046fdac348a7ad246966250d2561c951 /src/backend/utils/adt/jsonfuncs.c
parente45f8f882055d5f864815aa29ffcd2b5e3c2013b (diff)
downloadpostgresql-544ccf644288132f805260c4eb9fd12029c5cf8c.tar.gz
postgresql-544ccf644288132f805260c4eb9fd12029c5cf8c.zip
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 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;
}