Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c7a9834

Browse files
author
Nikita Glukhov
committed
Fix validation of $ and @ usages in jsonpath
1 parent cfef6b0 commit c7a9834

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
9191
{
9292
int32 left, right;
9393

94-
forbiddenRoot = true;
9594
left = buf->len;
9695

9796
/*
@@ -102,9 +101,9 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
102101
right = buf->len;
103102
appendBinaryStringInfo(buf, (char*)&right /* fake value */, sizeof(right));
104103

105-
chld = flattenJsonPathParseItem(buf, item->value.args.left, true);
104+
chld = flattenJsonPathParseItem(buf, item->value.args.left, forbiddenRoot);
106105
*(int32*)(buf->data + left) = chld;
107-
chld = flattenJsonPathParseItem(buf, item->value.args.right, true);
106+
chld = flattenJsonPathParseItem(buf, item->value.args.right, forbiddenRoot);
108107
*(int32*)(buf->data + right) = chld;
109108
}
110109
break;
@@ -120,8 +119,9 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
120119
arg = buf->len;
121120
appendBinaryStringInfo(buf, (char*)&arg /* fake value */, sizeof(arg));
122121

123-
forbiddenRoot = true;
124-
chld = flattenJsonPathParseItem(buf, item->value.arg, true);
122+
chld = flattenJsonPathParseItem(buf, item->value.arg,
123+
item->type == jpiFilter ||
124+
forbiddenRoot);
125125
*(int32*)(buf->data + arg) = chld;
126126
}
127127
break;
@@ -136,9 +136,15 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
136136
ereport(ERROR,
137137
(errcode(ERRCODE_SYNTAX_ERROR),
138138
errmsg("root is not allowed in expression")));
139+
break;
139140
case jpiAnyArray:
140141
case jpiAnyKey:
142+
break;
141143
case jpiCurrent:
144+
if (!forbiddenRoot)
145+
ereport(ERROR,
146+
(errcode(ERRCODE_SYNTAX_ERROR),
147+
errmsg("@ is not allowed in root expressions")));
142148
break;
143149
case jpiIndexArray:
144150
appendBinaryStringInfo(buf,

0 commit comments

Comments
 (0)