diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-08-03 00:10:39 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-08-03 00:10:39 +0000 |
| commit | 57641a165ffa7ef33c21c321a59104db7985df74 (patch) | |
| tree | c020491c51955d51a84020a2961e9656aebaff6d /src/backend/utils/adt/tsquery_op.c | |
| parent | 57d9aefcaa1e16a3eb65ec7f03b8f8f24825f88e (diff) | |
| download | postgresql-57641a165ffa7ef33c21c321a59104db7985df74.tar.gz | |
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/utils/adt/tsquery_op.c')
| -rw-r--r-- | src/backend/utils/adt/tsquery_op.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c index 2b453e0286..0b81ff5938 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.8 2010/01/02 16:57:55 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.9 2010/08/03 00:10:39 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)); @@ -247,20 +247,20 @@ tsq_mcontains(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } + iq = GETQUERY(query); ie = GETQUERY(ex); for (i = 0; i < ex->size; i++) { - iq = GETQUERY(query); if (ie[i].type != QI_VAL) continue; for (j = 0; j < query->size; j++) - if (iq[j].type == QI_VAL && ie[i].qoperand.valcrc == iq[j].qoperand.valcrc) - { - j = query->size + 1; + { + if (iq[j].type == QI_VAL && + ie[i].qoperand.valcrc == iq[j].qoperand.valcrc) break; - } - if (j == query->size) + } + if (j >= query->size) { PG_FREE_IF_COPY(query, 0); PG_FREE_IF_COPY(ex, 1); |
