1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

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
This commit is contained in:
Andrew Dunstan
2015-10-04 13:28:16 -04:00
parent e45f8f8820
commit 544ccf6442
4 changed files with 25 additions and 31 deletions

View File

@ -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;
}