]> granicus.if.org Git - postgresql/commitdiff
Fix core dump in QTNodeCompare when tsquery_cmp() is applied to two empty
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Aug 2010 00:10:58 +0000 (00:10 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Aug 2010 00:10:58 +0000 (00:10 +0000)
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().

src/backend/utils/adt/tsquery_op.c
src/backend/utils/adt/tsquery_util.c

index a0b103984dd713aa40d654e42e13d7e6ee7c1bcf..f3c40de5f2efb5aade3baeddddcd9ef0c04aa4b8 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.3.2.2 2008/03/09 10:42:48 teodor Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.3.2.3 2010/08/03 00:10:58 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));
index b81835c9692a2ddea80c07bfd224ea1842dec68d..fd5430ce166c79370ecc4c398a4b4817e0a18a70 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.8 2008/01/01 19:45:53 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_util.c,v 1.8.2.1 2010/08/03 00:10:58 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;
@@ -130,6 +128,11 @@ QTNodeCompare(QTNode *an, QTNode *bn)
                else
                        return (ao->length > bo->length) ? -1 : 1;
        }
+       else
+       {
+               elog(ERROR, "unrecognized QueryItem type: %d", an->valnode->type);
+               return 0;                               /* keep compiler quiet */
+       }
 }
 
 static int