Skip to content

Commit 2271d00

Browse files
committed
Fix "path" infrastructure bug affecting jsonb_set()
jsonb_set() and other clients of the setPathArray() utility function could get spurious results when an array integer subscript is provided that is not within the range of int. To fix, ensure that the value returned by strtol() within setPathArray() is within the range of int; when it isn't, assume an invalid input in line with existing, similar cases. The path-orientated operators that appeared in PostgreSQL 9.3 and 9.4 do not call setPathArray(), and already independently take this precaution, so no change there. Peter Geoghegan
1 parent ae58f14 commit 2271d00

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,11 +3814,14 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
38143814
if (level < path_len && !path_nulls[level])
38153815
{
38163816
char *c = VARDATA_ANY(path_elems[level]);
3817+
long lindex;
38173818

38183819
errno = 0;
3819-
idx = (int) strtol(c, &badp, 10);
3820-
if (errno != 0 || badp == c)
3820+
lindex = strtol(c, &badp, 10);
3821+
if (errno != 0 || badp == c || lindex > INT_MAX || lindex < INT_MIN)
38213822
idx = nelems;
3823+
else
3824+
idx = lindex;
38223825
}
38233826
else
38243827
idx = nelems;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy