diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-09-03 01:34:55 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-09-03 01:34:55 +0000 |
commit | 303696c3b47e6719e983e93da5896ddc4a2e0dbb (patch) | |
tree | 0cf979aeaf94f5f4c45948c3db78755d08dde5a6 /src/test | |
parent | 8ab6a6b4562efcd9f320353d5438fdbe10dbf9c5 (diff) | |
download | postgresql-REL9_1_ALPHA1.tar.gz postgresql-REL9_1_ALPHA1.zip |
Install a data-type-based solution for protecting pg_get_expr().REL9_1_ALPHA1
Since the code underlying pg_get_expr() is not secure against malformed
input, and can't practically be made so, we need to prevent miscreants
from feeding arbitrary data to it. We can do this securely by declaring
pg_get_expr() to take a new datatype "pg_node_tree" and declaring the
system catalog columns that hold nodeToString output to be of that type.
There is no way at SQL level to create a non-null value of type pg_node_tree.
Since the backend-internal operations that fill those catalog columns
operate below the SQL level, they are oblivious to the datatype relabeling
and don't need any changes.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/opr_sanity.out | 23 | ||||
-rw-r--r-- | src/test/regress/expected/type_sanity.out | 9 | ||||
-rw-r--r-- | src/test/regress/sql/opr_sanity.sql | 5 | ||||
-rw-r--r-- | src/test/regress/sql/type_sanity.sql | 2 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/test/regress/expected/opr_sanity.out b/src/test/regress/expected/opr_sanity.out index f6fee25de55..4703d497c1b 100644 --- a/src/test/regress/expected/opr_sanity.out +++ b/src/test/regress/expected/opr_sanity.out @@ -400,22 +400,25 @@ WHERE c.castfunc = p.oid AND -- As of 8.3, this finds the casts from xml to text, varchar, and bpchar, -- because those are binary-compatible while the reverse goes through -- texttoxml(), which does an XML syntax check. -SELECT * +-- As of 9.1, this finds the cast from pg_node_tree to text, which we +-- intentionally do not provide a reverse pathway for. +SELECT castsource::regtype, casttarget::regtype, castfunc, castcontext FROM pg_cast c WHERE c.castmethod = 'b' AND NOT EXISTS (SELECT 1 FROM pg_cast k WHERE k.castmethod = 'b' AND k.castsource = c.casttarget AND k.casttarget = c.castsource); - castsource | casttarget | castfunc | castcontext | castmethod -------------+------------+----------+-------------+------------ - 25 | 1042 | 0 | i | b - 1043 | 1042 | 0 | i | b - 650 | 869 | 0 | i | b - 142 | 25 | 0 | a | b - 142 | 1043 | 0 | a | b - 142 | 1042 | 0 | a | b -(6 rows) + castsource | casttarget | castfunc | castcontext +-------------------+-------------------+----------+------------- + text | character | 0 | i + character varying | character | 0 | i + pg_node_tree | text | 0 | i + cidr | inet | 0 | i + xml | text | 0 | a + xml | character varying | 0 | a + xml | character | 0 | a +(7 rows) -- **************** pg_operator **************** -- Look for illegal values in pg_operator fields. diff --git a/src/test/regress/expected/type_sanity.out b/src/test/regress/expected/type_sanity.out index be86ee313be..b7433653d1e 100644 --- a/src/test/regress/expected/type_sanity.out +++ b/src/test/regress/expected/type_sanity.out @@ -57,18 +57,19 @@ WHERE (p1.typtype = 'c' AND p1.typrelid = 0) OR (0 rows) -- Look for basic or enum types that don't have an array type. --- NOTE: as of 8.0, this check finds smgr and unknown. +-- NOTE: as of 9.1, this check finds pg_node_tree, smgr, and unknown. SELECT p1.oid, p1.typname FROM pg_type as p1 WHERE p1.typtype in ('b','e') AND p1.typname NOT LIKE E'\\_%' AND NOT EXISTS (SELECT 1 FROM pg_type as p2 WHERE p2.typname = ('_' || p1.typname)::name AND p2.typelem = p1.oid and p1.typarray = p2.oid); - oid | typname ------+--------- + oid | typname +-----+-------------- + 194 | pg_node_tree 210 | smgr 705 | unknown -(2 rows) +(3 rows) -- Make sure typarray points to a varlena array type of our own base SELECT p1.oid, p1.typname as basetype, p2.typname as arraytype, diff --git a/src/test/regress/sql/opr_sanity.sql b/src/test/regress/sql/opr_sanity.sql index 46ec24cca6f..0d084a1f7a6 100644 --- a/src/test/regress/sql/opr_sanity.sql +++ b/src/test/regress/sql/opr_sanity.sql @@ -318,7 +318,10 @@ WHERE c.castfunc = p.oid AND -- because those are binary-compatible while the reverse goes through -- texttoxml(), which does an XML syntax check. -SELECT * +-- As of 9.1, this finds the cast from pg_node_tree to text, which we +-- intentionally do not provide a reverse pathway for. + +SELECT castsource::regtype, casttarget::regtype, castfunc, castcontext FROM pg_cast c WHERE c.castmethod = 'b' AND NOT EXISTS (SELECT 1 FROM pg_cast k diff --git a/src/test/regress/sql/type_sanity.sql b/src/test/regress/sql/type_sanity.sql index 265ef5e26e2..479bf8542a7 100644 --- a/src/test/regress/sql/type_sanity.sql +++ b/src/test/regress/sql/type_sanity.sql @@ -51,7 +51,7 @@ WHERE (p1.typtype = 'c' AND p1.typrelid = 0) OR (p1.typtype != 'c' AND p1.typrelid != 0); -- Look for basic or enum types that don't have an array type. --- NOTE: as of 8.0, this check finds smgr and unknown. +-- NOTE: as of 9.1, this check finds pg_node_tree, smgr, and unknown. SELECT p1.oid, p1.typname FROM pg_type as p1 |