Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."
authorTom Lane <[email protected]>
Sun, 19 Dec 2010 17:48:34 +0000 (12:48 -0500)
committerTom Lane <[email protected]>
Sun, 19 Dec 2010 17:48:34 +0000 (12:48 -0500)
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.

contrib/intarray/_int_bool.c
contrib/ltree/ltxtquery_io.c
src/backend/utils/adt/tsquery.c

index 7557c6acb720d692990fe7e65fbcb205c5a36152..4cc447bab2d0f943e67d045932e1a4421625f039 100644 (file)
@@ -196,8 +196,8 @@ makepol(WORKSTATE *state)
            case OPEN:
                if (makepol(state) == ERR)
                    return ERR;
-               if (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-                                stack[lenstack - 1] == (int4) '!'))
+               while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
+                                   stack[lenstack - 1] == (int4) '!'))
                {
                    lenstack--;
                    pushquery(state, OPR, stack[lenstack]);
index e1240c3d2fe4f9420e91c7a1300e04d017ce1a54..826f4e1c9ddcf0120862565786745148abd61732 100644 (file)
@@ -241,8 +241,8 @@ makepol(QPRS_STATE *state)
            case OPEN:
                if (makepol(state) == ERR)
                    return ERR;
-               if (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-                                stack[lenstack - 1] == (int4) '!'))
+               while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
+                                   stack[lenstack - 1] == (int4) '!'))
                {
                    lenstack--;
                    pushquery(state, OPR, stack[lenstack], 0, 0, 0);
index db9236a474157a7851e2a80516e865c050543634..a155c933e264f3184378debca62b140a75096fa6 100644 (file)
@@ -371,8 +371,8 @@ makepol(TSQueryParserState state,
            case PT_OPEN:
                makepol(state, pushval, opaque);
 
-               if (lenstack && (opstack[lenstack - 1] == OP_AND ||
-                                opstack[lenstack - 1] == OP_NOT))
+               while (lenstack && (opstack[lenstack - 1] == OP_AND ||
+                                   opstack[lenstack - 1] == OP_NOT))
                {
                    lenstack--;
                    pushOperator(state, opstack[lenstack]);