Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8e2b6d4

Browse files
committed
Fix server crash bug in 'server' backup target.
When this code executed as superuser it appeared to work because no system catalog lookups happened, but otherwise it crashes because there is no transaction environment. Fix that. Report and code change by me. Test case by Dagfinn Ilmari Mannsåker. Discussion: http://postgr.es/m/CA+TgmobiKLXne-2AVzYyWRiO8=rChBQ=7ywoxp=2SmcFw=oDDw@mail.gmail.com
1 parent 87669de commit 8e2b6d4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/backend/replication/basebackup_server.c

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#include "postgres.h"
1212

13+
#include "access/xact.h"
1314
#include "catalog/pg_authid.h"
1415
#include "miscadmin.h"
1516
#include "replication/basebackup.h"
@@ -67,10 +68,12 @@ bbsink_server_new(bbsink *next, char *pathname)
6768
sink->base.bbs_next = next;
6869

6970
/* Replication permission is not sufficient in this case. */
71+
StartTransactionCommand();
7072
if (!is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES))
7173
ereport(ERROR,
7274
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
7375
errmsg("must be superuser or a member of the pg_write_server_files role to create server backup")));
76+
CommitTransactionCommand();
7477

7578
/*
7679
* It's not a good idea to store your backups in the same directory that

src/bin/pg_basebackup/t/010_pg_basebackup.pl

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Fcntl qw(:seek);
1111
use PostgreSQL::Test::Cluster;
1212
use PostgreSQL::Test::Utils;
13-
use Test::More tests => 143;
13+
use Test::More;
1414

1515
program_help_ok('pg_basebackup');
1616
program_version_ok('pg_basebackup');
@@ -521,6 +521,15 @@
521521
ok(-f "$tempdir/backuponserver/base.tar", 'backup tar was created');
522522
rmtree("$tempdir/backuponserver");
523523

524+
$node->command_ok(
525+
[qw(createuser --replication --role=pg_write_server_files backupuser)],
526+
'create backup user');
527+
$node->command_ok(
528+
[ @pg_basebackup_defs, '-U', 'backupuser', '--target', "server:$real_tempdir/backuponserver", '-X', 'none' ],
529+
'backup target server');
530+
ok(-f "$tempdir/backuponserver/base.tar", 'backup tar was created as non-superuser');
531+
rmtree("$tempdir/backuponserver");
532+
524533
$node->command_fails(
525534
[
526535
@pg_basebackup_defs, '-D',
@@ -768,3 +777,5 @@
768777
rmtree("$tempdir/backup_gzip2");
769778
rmtree("$tempdir/backup_gzip3");
770779
}
780+
781+
done_testing();

0 commit comments

Comments
 (0)