From: Tom Lane Date: Sun, 19 Dec 2010 17:48:58 +0000 (-0500) Subject: Fix erroneous parsing of tsquery input "... & !(subexpression) | ..." X-Git-Tag: REL8_2_20~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b053c532489a3fa1e01b196c15a0f14138ee9c3a;p=thirdparty%2Fpostgresql.git 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. --- diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c index 8517010e5ed..64c8e00e2f3 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 ca6325adf72..44fcc954ece 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/contrib/tsearch2/query.c b/contrib/tsearch2/query.c index c86169874cb..8d313e16493 100644 --- a/contrib/tsearch2/query.c +++ b/contrib/tsearch2/query.c @@ -396,8 +396,8 @@ makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int, int case OPEN: if (makepol(state, pushval) == 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);