Skip to content

Commit b7a0e8f

Browse files
committed
Defend against null scankeys in spgist searches.
Should've thought of that one earlier.
1 parent 5577ca5 commit b7a0e8f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/backend/access/spgist/spgscan.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,22 @@ spgLeafTest(SpGistScanOpaque so, Datum leafDatum,
162162
oldCtx = MemoryContextSwitchTo(so->tempCxt);
163163
for (i = 0; i < so->numberOfKeys; i++)
164164
{
165-
in.strategy = so->keyData[i].sk_strategy;
166-
in.query = so->keyData[i].sk_argument;
165+
ScanKey skey = &so->keyData[i];
166+
167+
/* Assume SPGiST-indexable operators are strict */
168+
if (skey->sk_flags & SK_ISNULL)
169+
{
170+
result = false;
171+
break;
172+
}
173+
174+
in.strategy = skey->sk_strategy;
175+
in.query = skey->sk_argument;
167176

168177
out.recheck = false;
169178

170179
result = DatumGetBool(FunctionCall2Coll(&so->state.leafConsistentFn,
171-
so->keyData[i].sk_collation,
180+
skey->sk_collation,
172181
PointerGetDatum(&in),
173182
PointerGetDatum(&out)));
174183
*recheck |= out.recheck;
@@ -398,13 +407,22 @@ spgWalk(Relation index, SpGistScanOpaque so, bool scanWholeIndex,
398407

399408
for (j = 0; j < so->numberOfKeys; j++)
400409
{
401-
in.strategy = so->keyData[j].sk_strategy;
402-
in.query = so->keyData[j].sk_argument;
410+
ScanKey skey = &so->keyData[j];
411+
412+
/* Assume SPGiST-indexable operators are strict */
413+
if (skey->sk_flags & SK_ISNULL)
414+
{
415+
nMatches = 0;
416+
break;
417+
}
418+
419+
in.strategy = skey->sk_strategy;
420+
in.query = skey->sk_argument;
403421

404422
memset(&out, 0, sizeof(out));
405423

406424
FunctionCall2Coll(&so->state.innerConsistentFn,
407-
so->keyData[j].sk_collation,
425+
skey->sk_collation,
408426
PointerGetDatum(&in),
409427
PointerGetDatum(&out));
410428

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy