|
| 1 | +/* |
| 2 | + * Check fix for CVE-2020-14350. |
| 3 | + * See also 7eeb1d986 postgresql commit. |
| 4 | + */ |
| 5 | +SET client_min_messages = 'warning'; |
| 6 | +DROP FUNCTION IF EXISTS _partition_data_concurrent(oid,integer); |
| 7 | +DROP FUNCTION IF EXISTS create_single_range_partition(TEXT,ANYELEMENT,ANYELEMENT,TEXT); |
| 8 | +DROP TABLE IF EXISTS test1 CASCADE; |
| 9 | +DROP TABLE IF EXISTS test2 CASCADE; |
| 10 | +DROP ROLE IF EXISTS regress_hacker; |
| 11 | +SET client_min_messages = 'notice'; |
| 12 | +CREATE EXTENSION pg_pathman; |
| 13 | +CREATE ROLE regress_hacker LOGIN; |
| 14 | +-- Test 1 |
| 15 | +RESET ROLE; |
| 16 | +ALTER ROLE regress_hacker NOSUPERUSER; |
| 17 | +SET ROLE regress_hacker; |
| 18 | +SHOW is_superuser; |
| 19 | + is_superuser |
| 20 | +-------------- |
| 21 | + off |
| 22 | +(1 row) |
| 23 | + |
| 24 | +CREATE FUNCTION _partition_data_concurrent(relation oid, p_limit INT, OUT p_total BIGINT) |
| 25 | +RETURNS bigint |
| 26 | +AS $$ |
| 27 | +BEGIN |
| 28 | + ALTER ROLE regress_hacker SUPERUSER; |
| 29 | + SELECT _partition_data_concurrent(relation, NULL::text, NULL::text, p_limit) INTO p_total; |
| 30 | +END |
| 31 | +$$ LANGUAGE plpgsql; |
| 32 | +CREATE TABLE test1(i INT4 NOT NULL); |
| 33 | +INSERT INTO test1 SELECT generate_series(1, 500); |
| 34 | +SELECT create_hash_partitions('test1', 'i', 5, false); |
| 35 | + create_hash_partitions |
| 36 | +------------------------ |
| 37 | + 5 |
| 38 | +(1 row) |
| 39 | + |
| 40 | +RESET ROLE; |
| 41 | +SELECT partition_table_concurrently('test1', 10, 1); |
| 42 | +NOTICE: worker started, you can stop it with the following command: select public.stop_concurrent_part_task('test1'); |
| 43 | + partition_table_concurrently |
| 44 | +------------------------------ |
| 45 | + |
| 46 | +(1 row) |
| 47 | + |
| 48 | +SELECT pg_sleep(1); |
| 49 | + pg_sleep |
| 50 | +---------- |
| 51 | + |
| 52 | +(1 row) |
| 53 | + |
| 54 | +-- Test result (must be 'off') |
| 55 | +SET ROLE regress_hacker; |
| 56 | +SHOW is_superuser; |
| 57 | + is_superuser |
| 58 | +-------------- |
| 59 | + off |
| 60 | +(1 row) |
| 61 | + |
| 62 | +-- Test 2 |
| 63 | +RESET ROLE; |
| 64 | +ALTER ROLE regress_hacker NOSUPERUSER; |
| 65 | +SET ROLE regress_hacker; |
| 66 | +SHOW is_superuser; |
| 67 | + is_superuser |
| 68 | +-------------- |
| 69 | + off |
| 70 | +(1 row) |
| 71 | + |
| 72 | +CREATE FUNCTION create_single_range_partition(parent_relid TEXT, start_value ANYELEMENT, end_value ANYELEMENT, partition_name TEXT) |
| 73 | +RETURNS REGCLASS |
| 74 | +AS $$ |
| 75 | +BEGIN |
| 76 | + ALTER ROLE regress_hacker SUPERUSER; |
| 77 | + RETURN create_single_range_partition(parent_relid, start_value, end_value, partition_name, NULL::text); |
| 78 | +END |
| 79 | +$$ LANGUAGE plpgsql; |
| 80 | +RESET ROLE; |
| 81 | +CREATE TABLE test2(i INT4 NOT NULL); |
| 82 | +INSERT INTO test2 VALUES(0); |
| 83 | +SELECT create_range_partitions('test2', 'i', 0, 1); |
| 84 | + create_range_partitions |
| 85 | +------------------------- |
| 86 | + 1 |
| 87 | +(1 row) |
| 88 | + |
| 89 | +INSERT INTO test2 values(1); |
| 90 | +-- Test result (must be 'off') |
| 91 | +SET ROLE regress_hacker; |
| 92 | +SHOW is_superuser; |
| 93 | + is_superuser |
| 94 | +-------------- |
| 95 | + off |
| 96 | +(1 row) |
| 97 | + |
| 98 | +-- Cleanup |
| 99 | +RESET ROLE; |
| 100 | +DROP FUNCTION _partition_data_concurrent(oid,integer); |
| 101 | +DROP FUNCTION create_single_range_partition(TEXT,ANYELEMENT,ANYELEMENT,TEXT); |
| 102 | +DROP TABLE test1 CASCADE; |
| 103 | +NOTICE: drop cascades to 5 other objects |
| 104 | +DETAIL: drop cascades to table test1_0 |
| 105 | +drop cascades to table test1_1 |
| 106 | +drop cascades to table test1_2 |
| 107 | +drop cascades to table test1_3 |
| 108 | +drop cascades to table test1_4 |
| 109 | +DROP TABLE test2 CASCADE; |
| 110 | +NOTICE: drop cascades to 3 other objects |
| 111 | +DETAIL: drop cascades to sequence test2_seq |
| 112 | +drop cascades to table test2_1 |
| 113 | +drop cascades to table test2_2 |
| 114 | +DROP ROLE regress_hacker; |
| 115 | +DROP EXTENSION pg_pathman; |
0 commit comments