1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Fix nested NOT operation cleanup in tsquery.

During normalization of tsquery tree it tries to simplify nested NOT
operations but there it's obvioulsy missed that subsequent node could be
a leaf node (value node)

Bug #14245: Segfault on weird to_tsquery
Reported by David Kellum.
This commit is contained in:
Teodor Sigaev
2016-07-15 19:22:18 +03:00
parent ce150e7e0f
commit 19d290155d
3 changed files with 22 additions and 1 deletions

View File

@ -406,6 +406,8 @@ normalize_phrase_tree(NODE *node)
if (node->valnode->qoperator.oper == OP_NOT)
{
NODE *orignode = node;
/* eliminate NOT sequence */
while (node->valnode->type == QI_OPR &&
node->valnode->qoperator.oper == node->right->valnode->qoperator.oper)
@ -413,6 +415,10 @@ normalize_phrase_tree(NODE *node)
node = node->right->right;
}
if (orignode != node)
/* current node isn't checked yet */
node = normalize_phrase_tree(node);
else
node->right = normalize_phrase_tree(node->right);
}
else if (node->valnode->qoperator.oper == OP_PHRASE)

View File

@ -555,6 +555,18 @@ SELECT plainto_tsquery('english', 'foo bar') && 'asd | fg';
(1 row)
-- Check stop word deletion, a and s are stop-words
SELECT to_tsquery('english', '!(a & !b) & c');
to_tsquery
------------
'b' & 'c'
(1 row)
SELECT to_tsquery('english', '!(a & !b)');
to_tsquery
------------
'b'
(1 row)
SELECT to_tsquery('english', '(1 <-> 2) <-> a');
to_tsquery
-------------

View File

@ -130,6 +130,9 @@ SELECT plainto_tsquery('english', 'foo bar') || !!plainto_tsquery('english', 'as
SELECT plainto_tsquery('english', 'foo bar') && 'asd | fg';
-- Check stop word deletion, a and s are stop-words
SELECT to_tsquery('english', '!(a & !b) & c');
SELECT to_tsquery('english', '!(a & !b)');
SELECT to_tsquery('english', '(1 <-> 2) <-> a');
SELECT to_tsquery('english', '(1 <-> a) <-> 2');
SELECT to_tsquery('english', '(a <-> 1) <-> 2');