Commit abc10262 authored by Tom Lane's avatar Tom Lane

Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."

After parsing a parenthesized subexpression, we must pop all pending
ANDs and NOTs off the stack, just like the case for a simple operand.
Per bug #5793.

Also fix clones of this routine in contrib/intarray and contrib/ltree,
where input of types query_int and ltxtquery had the same problem.

Back-patch to all supported versions.
parent dcb09b59
...@@ -196,7 +196,7 @@ makepol(WORKSTATE *state) ...@@ -196,7 +196,7 @@ makepol(WORKSTATE *state)
case OPEN: case OPEN:
if (makepol(state) == ERR) if (makepol(state) == ERR)
return ERR; return ERR;
if (lenstack && (stack[lenstack - 1] == (int4) '&' || while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!')) stack[lenstack - 1] == (int4) '!'))
{ {
lenstack--; lenstack--;
......
...@@ -241,7 +241,7 @@ makepol(QPRS_STATE *state) ...@@ -241,7 +241,7 @@ makepol(QPRS_STATE *state)
case OPEN: case OPEN:
if (makepol(state) == ERR) if (makepol(state) == ERR)
return ERR; return ERR;
if (lenstack && (stack[lenstack - 1] == (int4) '&' || while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!')) stack[lenstack - 1] == (int4) '!'))
{ {
lenstack--; lenstack--;
......
...@@ -371,7 +371,7 @@ makepol(TSQueryParserState state, ...@@ -371,7 +371,7 @@ makepol(TSQueryParserState state,
case PT_OPEN: case PT_OPEN:
makepol(state, pushval, opaque); makepol(state, pushval, opaque);
if (lenstack && (opstack[lenstack - 1] == OP_AND || while (lenstack && (opstack[lenstack - 1] == OP_AND ||
opstack[lenstack - 1] == OP_NOT)) opstack[lenstack - 1] == OP_NOT))
{ {
lenstack--; lenstack--;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment