1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-22 02:52:08 +03:00

Add tests for various connection string issues

Add tests for consistent support of connection strings in frontend
programs as well as proper handling of unusual characters in database
and user names.  These tests were developed for the issues of
CVE-2016-5424.

To allow testing of names with spaces, change the pg_regress
command-line options --create-role and --dbname to split their arguments
by comma only, not space or comma as before.  Only commas were actually
used in existing uses.

Noah Misch, Michael Paquier, Peter Eisentraut
This commit is contained in:
Peter Eisentraut
2016-08-04 14:44:23 -04:00
parent e7010ce479
commit 8b845520fb
9 changed files with 266 additions and 12 deletions

View File

@ -243,7 +243,13 @@ sub connstr
{
return "port=$pgport host=$pghost";
}
return "port=$pgport host=$pghost dbname=$dbname";
# Escape properly the database string before using it, only
# single quotes and backslashes need to be treated this way.
$dbname =~ s#\\#\\\\#g;
$dbname =~ s#\'#\\\'#g;
return "port=$pgport host=$pghost dbname='$dbname'";
}
=pod
@ -396,7 +402,8 @@ sub init
mkdir $self->backup_dir;
mkdir $self->archive_dir;
TestLib::system_or_bail('initdb', '-D', $pgdata, '-A', 'trust', '-N');
TestLib::system_or_bail('initdb', '-D', $pgdata, '-A', 'trust', '-N',
@{ $params{extra} });
TestLib::system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
open my $conf, ">>$pgdata/postgresql.conf";
@ -1300,6 +1307,24 @@ sub issues_sql_like
=pod
=item $node->run_log(...)
Runs a shell command like TestLib::run_log, but with PGPORT set so
that the command will default to connecting to this PostgresNode.
=cut
sub run_log
{
my $self = shift;
local $ENV{PGPORT} = $self->port;
TestLib::run_log(@_);
}
=pod
=back
=cut