]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Avoid fetching past the end of the indoption array.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Apr 2019 22:18:59 +0000 (18:18 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Apr 2019 22:18:59 +0000 (18:18 -0400)
pg_get_indexdef_worker carelessly fetched indoption entries even for
non-key index columns that don't have one.  99.999% of the time this
would be harmless, since the code wouldn't examine the value ... but
some fine day this will be a fetch off the end of memory, resulting
in SIGSEGV.

Detected through valgrind testing.  Odd that the buildfarm's valgrind
critters haven't noticed.

src/backend/utils/adt/ruleutils.c

index 01ad716605ca78b3dcd1cf57b642b225d018576e..54f5cac1e3e80e7b06e3ab23b5d30f96e5aa159d 100644 (file)
@@ -1305,7 +1305,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
        for (keyno = 0; keyno < idxrec->indnatts; keyno++)
        {
                AttrNumber      attnum = idxrec->indkey.values[keyno];
-               int16           opt = indoption->values[keyno];
                Oid                     keycoltype;
                Oid                     keycolcollation;
 
@@ -1367,10 +1366,10 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
                if (!attrsOnly && keyno < idxrec->indnkeyatts &&
                        (!colno || colno == keyno + 1))
                {
-                       Oid                     indcoll;
+                       int16           opt = indoption->values[keyno];
+                       Oid                     indcoll = indcollation->values[keyno];
 
                        /* Add collation, if not default for column */
-                       indcoll = indcollation->values[keyno];
                        if (OidIsValid(indcoll) && indcoll != keycolcollation)
                                appendStringInfo(&buf, " COLLATE %s",
                                                                 generate_collation_name((indcoll)));