Skip to content

Commit 36faa15

Browse files
committed
fix create_single_range_partition
1 parent c505977 commit 36faa15

File tree

3 files changed

+99
-20
lines changed

3 files changed

+99
-20
lines changed

expected/pathman_CVE-2020-14350.out

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
*/
55
SET client_min_messages = 'warning';
66
DROP FUNCTION IF EXISTS _partition_data_concurrent(oid,integer);
7-
DROP TABLE IF EXISTS conc_part CASCADE;
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;
810
DROP ROLE IF EXISTS regress_hacker;
911
SET client_min_messages = 'notice';
1012
CREATE EXTENSION pg_pathman;
1113
CREATE ROLE regress_hacker LOGIN;
14+
-- Test 1
15+
RESET ROLE;
16+
ALTER ROLE regress_hacker NOSUPERUSER;
1217
SET ROLE regress_hacker;
1318
SHOW is_superuser;
1419
is_superuser
@@ -24,17 +29,17 @@ BEGIN
2429
SELECT _partition_data_concurrent(relation, NULL::text, NULL::text, p_limit) INTO p_total;
2530
END
2631
$$ LANGUAGE plpgsql;
27-
CREATE TABLE conc_part(id INT4 NOT NULL);
28-
INSERT INTO conc_part SELECT generate_series(1, 500);
29-
SELECT create_hash_partitions('conc_part', 'id', 5, false);
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);
3035
create_hash_partitions
3136
------------------------
3237
5
3338
(1 row)
3439

3540
RESET ROLE;
36-
SELECT partition_table_concurrently('conc_part', 10, 1);
37-
NOTICE: worker started, you can stop it with the following command: select public.stop_concurrent_part_task('conc_part');
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');
3843
partition_table_concurrently
3944
------------------------------
4045

@@ -54,15 +59,57 @@ SHOW is_superuser;
5459
off
5560
(1 row)
5661

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+
5798
-- Cleanup
5899
RESET ROLE;
59100
DROP FUNCTION _partition_data_concurrent(oid,integer);
60-
DROP TABLE conc_part CASCADE;
101+
DROP FUNCTION create_single_range_partition(TEXT,ANYELEMENT,ANYELEMENT,TEXT);
102+
DROP TABLE test1 CASCADE;
61103
NOTICE: drop cascades to 5 other objects
62-
DETAIL: drop cascades to table conc_part_0
63-
drop cascades to table conc_part_1
64-
drop cascades to table conc_part_2
65-
drop cascades to table conc_part_3
66-
drop cascades to table conc_part_4
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
67114
DROP ROLE regress_hacker;
68115
DROP EXTENSION pg_pathman;

sql/pathman_CVE-2020-14350.sql

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55

66
SET client_min_messages = 'warning';
77
DROP FUNCTION IF EXISTS _partition_data_concurrent(oid,integer);
8-
DROP TABLE IF EXISTS conc_part CASCADE;
8+
DROP FUNCTION IF EXISTS create_single_range_partition(TEXT,ANYELEMENT,ANYELEMENT,TEXT);
9+
DROP TABLE IF EXISTS test1 CASCADE;
10+
DROP TABLE IF EXISTS test2 CASCADE;
911
DROP ROLE IF EXISTS regress_hacker;
1012
SET client_min_messages = 'notice';
1113

1214
CREATE EXTENSION pg_pathman;
1315
CREATE ROLE regress_hacker LOGIN;
1416

17+
-- Test 1
18+
RESET ROLE;
19+
ALTER ROLE regress_hacker NOSUPERUSER;
20+
1521
SET ROLE regress_hacker;
1622
SHOW is_superuser;
17-
1823
CREATE FUNCTION _partition_data_concurrent(relation oid, p_limit INT, OUT p_total BIGINT)
1924
RETURNS bigint
2025
AS $$
@@ -24,22 +29,49 @@ BEGIN
2429
END
2530
$$ LANGUAGE plpgsql;
2631

27-
CREATE TABLE conc_part(id INT4 NOT NULL);
28-
INSERT INTO conc_part SELECT generate_series(1, 500);
29-
SELECT create_hash_partitions('conc_part', 'id', 5, false);
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);
3035

3136
RESET ROLE;
32-
SELECT partition_table_concurrently('conc_part', 10, 1);
37+
SELECT partition_table_concurrently('test1', 10, 1);
3338
SELECT pg_sleep(1);
3439

3540
-- Test result (must be 'off')
3641
SET ROLE regress_hacker;
3742
SHOW is_superuser;
3843

44+
-- Test 2
45+
RESET ROLE;
46+
ALTER ROLE regress_hacker NOSUPERUSER;
47+
48+
SET ROLE regress_hacker;
49+
SHOW is_superuser;
50+
CREATE FUNCTION create_single_range_partition(parent_relid TEXT, start_value ANYELEMENT, end_value ANYELEMENT, partition_name TEXT)
51+
RETURNS REGCLASS
52+
AS $$
53+
BEGIN
54+
ALTER ROLE regress_hacker SUPERUSER;
55+
RETURN create_single_range_partition(parent_relid, start_value, end_value, partition_name, NULL::text);
56+
END
57+
$$ LANGUAGE plpgsql;
58+
59+
RESET ROLE;
60+
CREATE TABLE test2(i INT4 NOT NULL);
61+
INSERT INTO test2 VALUES(0);
62+
SELECT create_range_partitions('test2', 'i', 0, 1);
63+
INSERT INTO test2 values(1);
64+
65+
-- Test result (must be 'off')
66+
SET ROLE regress_hacker;
67+
SHOW is_superuser;
68+
3969
-- Cleanup
4070
RESET ROLE;
4171
DROP FUNCTION _partition_data_concurrent(oid,integer);
42-
DROP TABLE conc_part CASCADE;
72+
DROP FUNCTION create_single_range_partition(TEXT,ANYELEMENT,ANYELEMENT,TEXT);
73+
DROP TABLE test1 CASCADE;
74+
DROP TABLE test2 CASCADE;
4375
DROP ROLE regress_hacker;
4476
DROP EXTENSION pg_pathman;
4577

src/partition_creation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ spawn_partitions_val(Oid parent_relid, /* parent's Oid */
604604

605605
/* Construct call to create_single_range_partition() */
606606
create_sql = psprintf(
607-
"select %s.create_single_range_partition('%s.%s', '%s'::%s, '%s'::%s, '%s.%s')",
607+
"select %s.create_single_range_partition('%s.%s'::regclass, '%s'::%s, '%s'::%s, '%s.%s', NULL::text)",
608608
quote_identifier(get_namespace_name(get_pathman_schema())),
609609
quote_identifier(parent_nsp_name),
610610
quote_identifier(get_rel_name(parent_relid)),

0 commit comments

Comments
 (0)