]> granicus.if.org Git - postgresql/commitdiff
Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 19 Dec 2010 17:48:53 +0000 (12:48 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 19 Dec 2010 17:48:53 +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 2344d0b50be110fcec542875332380dffcb79fae..8af6100214f9d861fd7d119e514c7ea85240262b 100644 (file)
@@ -189,8 +189,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 6c9a63d5dbb7485202d647a9935325d525e8b199..b87d05c0440c1db0ae301bf74ba9dd60b45ea4f8 100644 (file)
@@ -234,8 +234,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 4b0425965f3f787804d7057029038ace547a8867..4bbc3e0053351581357667baf29613dbd4c26394 100644 (file)
@@ -360,8 +360,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]);