diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2015-10-04 13:28:16 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2015-10-04 13:28:16 -0400 |
commit | 1edd4ec831458e10b524d1473a7de5791aa8753e (patch) | |
tree | 1b2f229c94932b0b92421e1b258b44f4f802cddf /src/backend/utils/adt/jsonfuncs.c | |
parent | 6390c8c654d07c08686adbbc595a13d76b573653 (diff) | |
download | postgresql-1edd4ec831458e10b524d1473a7de5791aa8753e.tar.gz postgresql-1edd4ec831458e10b524d1473a7de5791aa8753e.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.c | 5 |
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; } |