]> granicus.if.org Git - postgresql/commitdiff
Defend against null scankeys in spgist searches.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Dec 2011 00:08:28 +0000 (19:08 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Dec 2011 00:08:28 +0000 (19:08 -0500)
Should've thought of that one earlier.

src/backend/access/spgist/spgscan.c

index 1c6180b2d24b74cd6a746a9b6959eccb2a1871c8..ac309649682a41375b6fb385f35dd9124ba3d161 100644 (file)
@@ -162,13 +162,22 @@ spgLeafTest(SpGistScanOpaque so, Datum leafDatum,
        oldCtx = MemoryContextSwitchTo(so->tempCxt);
        for (i = 0; i < so->numberOfKeys; i++)
        {
-               in.strategy = so->keyData[i].sk_strategy;
-               in.query = so->keyData[i].sk_argument;
+               ScanKey         skey = &so->keyData[i];
+
+               /* Assume SPGiST-indexable operators are strict */
+               if (skey->sk_flags & SK_ISNULL)
+               {
+                       result = false;
+                       break;
+               }
+
+               in.strategy = skey->sk_strategy;
+               in.query = skey->sk_argument;
 
                out.recheck = false;
 
                result = DatumGetBool(FunctionCall2Coll(&so->state.leafConsistentFn,
-                                                                                               so->keyData[i].sk_collation,
+                                                                                               skey->sk_collation,
                                                                                                PointerGetDatum(&in),
                                                                                                PointerGetDatum(&out)));
                *recheck |= out.recheck;
@@ -398,13 +407,22 @@ redirect:
 
                                for (j = 0; j < so->numberOfKeys; j++)
                                {
-                                       in.strategy = so->keyData[j].sk_strategy;
-                                       in.query = so->keyData[j].sk_argument;
+                                       ScanKey         skey = &so->keyData[j];
+
+                                       /* Assume SPGiST-indexable operators are strict */
+                                       if (skey->sk_flags & SK_ISNULL)
+                                       {
+                                               nMatches = 0;
+                                               break;
+                                       }
+
+                                       in.strategy = skey->sk_strategy;
+                                       in.query = skey->sk_argument;
 
                                        memset(&out, 0, sizeof(out));
 
                                        FunctionCall2Coll(&so->state.innerConsistentFn,
-                                                                         so->keyData[j].sk_collation,
+                                                                         skey->sk_collation,
                                                                          PointerGetDatum(&in),
                                                                          PointerGetDatum(&out));