Skip to content

Commit 3a654bf

Browse files
committed
Add fix on security bug CVE-2020-14350.
Add A.Lakhin's security TAP-test.
1 parent 2e8bfa4 commit 3a654bf

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
2020
DATA = aqo--1.0.sql aqo--1.0--1.1.sql
2121
DATA_built = aqo--1.1.sql
2222

23+
TAP_TESTS = 1
24+
2325
MODULE_big = aqo
2426
ifdef USE_PGXS
2527
PG_CONFIG = pg_config

aqo--1.0--1.1.sql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ DROP INDEX public.aqo_query_texts_query_hash_idx CASCADE;
66
DROP INDEX public.aqo_query_stat_idx CASCADE;
77
DROP INDEX public.aqo_fss_access_idx CASCADE;
88

9-
CREATE UNIQUE INDEX aqo_fss_access_idx ON public.aqo_data (fspace_hash, fsspace_hash);
9+
CREATE UNIQUE INDEX aqo_fss_access_idx
10+
ON public.aqo_data (fspace_hash, fsspace_hash);
1011

1112

1213
CREATE OR REPLACE FUNCTION aqo_migrate_to_1_1_get_pk(rel regclass) RETURNS regclass AS $$
@@ -16,8 +17,7 @@ BEGIN
1617
SELECT i.indexrelid FROM pg_catalog.pg_index i JOIN
1718
pg_catalog.pg_attribute a ON a.attrelid = i.indrelid AND
1819
a.attnum = ANY(i.indkey)
19-
WHERE i.indrelid = rel AND
20-
i.indisprimary
20+
WHERE i.indrelid = rel AND i.indisprimary
2121
INTO idx;
2222

2323
RETURN idx;
@@ -27,19 +27,18 @@ $$ LANGUAGE plpgsql;
2727

2828
DO $$
2929
BEGIN
30-
EXECUTE format('ALTER TABLE %s RENAME to %s',
30+
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
3131
aqo_migrate_to_1_1_get_pk('public.aqo_queries'),
3232
'aqo_queries_query_hash_idx');
3333

34-
EXECUTE format('ALTER TABLE %s RENAME to %s',
34+
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
3535
aqo_migrate_to_1_1_get_pk('public.aqo_query_texts'),
3636
'aqo_query_texts_query_hash_idx');
3737

38-
EXECUTE format('ALTER TABLE %s RENAME to %s',
38+
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
3939
aqo_migrate_to_1_1_get_pk('public.aqo_query_stat'),
4040
'aqo_query_stat_idx');
4141
END
4242
$$;
4343

44-
4544
DROP FUNCTION aqo_migrate_to_1_1_get_pk(regclass);

t/000_security.pl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Acquiring superuser privileges
2+
use strict;
3+
use warnings;
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::More tests => 1;
7+
8+
my $node;
9+
10+
# Initialize node
11+
$node = get_new_node('node');
12+
$node->init;
13+
$node->start;
14+
15+
my $query;
16+
my $is_su;
17+
18+
print($node->safe_psql("postgres", "CREATE USER regress_hacker LOGIN"));
19+
$is_su = $node->safe_psql('postgres', undef,
20+
extra_params => [ '-U', 'regress_hacker', '-c', 'SHOW is_superuser' ]);
21+
diag("The regress_hacker is superuser: " . $is_su . "\n");
22+
23+
$query = q{
24+
CREATE FUNCTION format(f text, r regclass, t text)
25+
RETURNS text
26+
AS $$
27+
BEGIN
28+
ALTER ROLE regress_hacker SUPERUSER;
29+
RETURN '';
30+
END
31+
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
32+
};
33+
34+
print($node->safe_psql('postgres', undef,
35+
extra_params => [ '-U', 'regress_hacker', '-c', $query ]) . "\n");
36+
37+
$node->psql("postgres", "CREATE EXTENSION aqo");
38+
39+
$is_su = $node->safe_psql('postgres', undef,
40+
extra_params => [ '-U', 'regress_hacker', '-c', 'SHOW is_superuser' ]);
41+
42+
diag("The regress_hacker is superuser: " . $is_su . "\n");
43+
ok($is_su eq 'off');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy