Skip to content

Commit 7fe3c1e

Browse files
jcolemanjcoleman
authored andcommitted
Fix false positive non-superuser errors
Regex matching solely against the word "insufficient" means that it's trivial to cause this to alert unnecessarily by merely including the string "insufficient" in one's real query. Instead verify that we don't actually have a real query and know for certain this is an error condition.
1 parent 6b029f7 commit 7fe3c1e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

check_postgres.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8737,7 +8737,7 @@ sub check_txn_idle {
87378737
my $st = defined($r->{state}) ? $r->{state} : '';
87388738

87398739
## Return unknown if we cannot see because we are a non-superuser
8740-
if ($cq =~ /insufficient/) {
8740+
if ($cq eq '<insufficient privilege>') {
87418741
add_unknown msg('psa-nosuper');
87428742
return;
87438743
}

t/02_query_time.t

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use 5.008;
66
use strict;
77
use warnings;
88
use Data::Dumper;
9-
use Test::More tests => 14;
9+
use Test::More tests => 15;
1010
use lib 't','.';
1111
use CP_Testing;
1212

@@ -102,4 +102,26 @@ $dbh->disconnect();
102102

103103
waitpid $child, 0;
104104

105+
# Test that a query using the word insufficient doesn't trigger the unknown data alert.
106+
107+
$child = fork();
108+
if (0 == $child) {
109+
my $kiddbh = $cp->test_database_handle();
110+
$kiddbh->do(qq{SELECT pg_sleep(3) AS insufficient});
111+
$kiddbh->rollback();
112+
$kiddbh->disconnect();
113+
exit;
114+
}
115+
116+
my $dbh = $cp->test_database_handle();
117+
sleep 1;
118+
$t = qq{$S non-superuser access isn't fooled by the word insufficient};
119+
like ($cp->run(q{-w 1 -vv}), qr{$label WARNING}, $t);
120+
$dbh->rollback();
121+
$dbh->disconnect();
122+
123+
$dbh->disconnect();
124+
125+
waitpid $child, 0;
126+
105127
exit;

0 commit comments

Comments
 (0)