From d9b99b4b60fd0925b9e223ec9f5ea275a8c2dde5 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 19 Dec 2010 12:48:53 -0500 Subject: [PATCH] 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. --- contrib/intarray/_int_bool.c | 4 ++-- contrib/ltree/ltxtquery_io.c | 4 ++-- src/backend/utils/adt/tsquery.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c index 2344d0b50be..8af6100214f 100644 --- a/contrib/intarray/_int_bool.c +++ b/contrib/intarray/_int_bool.c @@ -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]); diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c index 6c9a63d5dbb..b87d05c0440 100644 --- a/contrib/ltree/ltxtquery_io.c +++ b/contrib/ltree/ltxtquery_io.c @@ -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); diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index 4b0425965f3..4bbc3e00533 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -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]);