aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-08-03 00:10:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-08-03 00:10:52 +0000
commit9f4b99afbb3861ab2344b1db62193b4673126ce5 (patch)
treea03a0a6a500de8b074ba12a050298800b70dcc89 /src/backend
parentc472e780a375c2aaf88b95f7c36cf4d74f453679 (diff)
downloadpostgresql-9f4b99afbb3861ab2344b1db62193b4673126ce5.tar.gz
postgresql-9f4b99afbb3861ab2344b1db62193b4673126ce5.zip
Fix core dump in QTNodeCompare when tsquery_cmp() is applied to two empty
tsqueries. CompareTSQ has to have a guard for the case rather than blindly applying QTNodeCompare to random data past the end of the datums. Also, change QTNodeCompare to be a little less trusting: use an actual test rather than just Assert'ing that the input is sane. Problem encountered while investigating another issue (I saw a core dump in autoanalyze on a table containing multiple empty tsquery values). Back-patch to all branches with tsquery support. In HEAD, also fix some bizarre (though not outright wrong) coding in tsq_mcontains().
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/utils/adt/tsquery_op.c4
-rw-r--r--src/backend/utils/adt/tsquery_util.c11
2 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c
index 6b7e976a431..41797b5e6a1 100644
--- a/src/backend/utils/adt/tsquery_op.c
+++ b/src/backend/utils/adt/tsquery_op.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.6 2009/06/11 14:49:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.6.2.1 2010/08/03 00:10:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -149,7 +149,7 @@ CompareTSQ(TSQuery a, TSQuery b)
{
return (VARSIZE(a) < VARSIZE(b)) ? -1 : 1;
}
- else
+ else if (a->size != 0)
{
QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a));
QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b));
diff --git a/src/backend/utils/adt/tsquery_util.c b/src/backend/utils/adt/tsquery_util.c
index 9efd5fa8d3b..831936696b7 100644
--- a/src/backend/utils/adt/tsquery_util.c
+++ b/src/backend/utils/adt/tsquery_util.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.11 2009/06/11 14:49:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.11.2.1 2010/08/03 00:10:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -113,13 +113,11 @@ QTNodeCompare(QTNode *an, QTNode *bn)
}
return 0;
}
- else
+ else if (an->valnode->type == QI_VAL)
{
QueryOperand *ao = &an->valnode->operand;
QueryOperand *bo = &bn->valnode->operand;
- Assert(an->valnode->type == QI_VAL);
-
if (ao->valcrc != bo->valcrc)
{
return (ao->valcrc > bo->valcrc) ? -1 : 1;
@@ -127,6 +125,11 @@ QTNodeCompare(QTNode *an, QTNode *bn)
return tsCompareString(an->word, ao->length, bn->word, bo->length, false);
}
+ else
+ {
+ elog(ERROR, "unrecognized QueryItem type: %d", an->valnode->type);
+ return 0; /* keep compiler quiet */
+ }
}
static int