pgbackrest.git / summary / log / commit / refs

commit    34afe5e85b682803dec846bfe480c82d3b3ca05c
Author:   David Steele <david@pgmasters.net>
Date:     Tue Aug 09 13:05:27 2016 +0000

    Fixed issue with tablespace link checking.
    
    * Tablespace paths that had $PGDATA as a substring would be identified as a subdirectories of $PGDATA even when they were not.
    * Also hardened relative path checking a bit.


doc/xml/release.xml | 17 +++++++++ lib/pgBackRest/FileCommon.pm | 9 ++++- lib/pgBackRest/Manifest.pm | 4 +- lib/pgBackRest/Version.pm | 2 +- test/expect/backup-synthetic-001.log | 40 ++++++++++++++++++++ test/lib/pgBackRestTest/Backup/BackupTest.pm | 55 +++++++++++++++++++++++++++- 6 files changed, 120 insertions(+), 7 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index ece80cc04..945ff6f0b 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -37,6 +37,11 @@ <contributor-id type="github">anarazel</contributor-id> </contributor> + <contributor id="fort.chris"> + <contributor-name-display>Chris Fort</contributor-name-display> + <contributor-id type="github">the1forte</contributor-id> + </contributor> + <contributor id="freund.andres"> <contributor-name-display>Andres Freund</contributor-name-display> <contributor-id type="github">anarazel</contributor-id> @@ -105,6 +110,18 @@ <release-list> <release date="XXXX-XX-XX" version="1.05dev" title="UNDER DEVELOPMENT"> + <release-core-list> + <release-bug-list> + <release-item> + <release-item-contributor-list> + <release-item-ideator id="fort.chris"/> + </release-item-contributor-list> + + <p>Fixed an issue where tablespace paths that had $PGDATA as a substring would be identified as a subdirectories of $PGDATA even when they were not. Also hardened relative path checking a bit.</p> + </release-item> + </release-bug-list> + </release-core-list> + <release-doc-list> <release-feature-list> <release-item> diff --git a/lib/pgBackRest/FileCommon.pm b/lib/pgBackRest/FileCommon.pm index d2874ec7b..d3fd99f31 100644 --- a/lib/pgBackRest/FileCommon.pm +++ b/lib/pgBackRest/FileCommon.pm @@ -738,10 +738,15 @@ sub pathAbsolute confess &log(ERROR, "${strBasePath} is not an absolute path", ERROR_PATH_TYPE); } - while (index($strPath, '../') == 0) + while (index($strPath, '..') == 0) { $strBasePath = dirname($strBasePath); - $strPath = substr($strPath, 3); + $strPath = substr($strPath, 2); + + if (index($strPath, '/') == 0) + { + $strPath = substr($strPath, 1); + } } $strAbsolutePath = "${strBasePath}/${strPath}"; diff --git a/lib/pgBackRest/Manifest.pm b/lib/pgBackRest/Manifest.pm index 44cc00ba6..8f6f7bb38 100644 --- a/lib/pgBackRest/Manifest.pm +++ b/lib/pgBackRest/Manifest.pm @@ -657,10 +657,10 @@ sub build } # Check for tablespaces in PGDATA - if (index($oManifestHash{name}{$strName}{link_destination}, $strPath) == 0 || + if (index($oManifestHash{name}{$strName}{link_destination}, "${strPath}/") == 0 || (index($oManifestHash{name}{$strName}{link_destination}, '/') != 0 && index(pathAbsolute($strPath . '/' . DB_PATH_PGTBLSPC, - $oManifestHash{name}{$strName}{link_destination}), $strPath) == 0)) + $oManifestHash{name}{$strName}{link_destination}) . '/', "${strPath}/") == 0)) { confess &log(ERROR, 'tablespace symlink ' . $oManifestHash{name}{$strName}{link_destination} . ' destination must not be in $PGDATA', ERROR_TABLESPACE_IN_PGDATA); diff --git a/lib/pgBackRest/Version.pm b/lib/pgBackRest/Version.pm index 90ef87147..f0f4ed214 100644 --- a/lib/pgBackRest/Version.pm +++ b/lib/pgBackRest/Version.pm @@ -27,7 +27,7 @@ use constant BACKREST_CONF => BACKREST_ # Defines the current version of the BackRest executable. The version number is used to track features but does not affect what # repositories or manifests can be read - that's the job of the format number. #----------------------------------------------------------------------------------------------------------------------------------- -use constant BACKREST_VERSION => '1.04'; +use constant BACKREST_VERSION => '1.05dev'; push @EXPORT, qw(BACKREST_VERSION); # Format Format Number diff --git a/test/expect/backup-synthetic-001.log b/test/expect/backup-synthetic-001.log index 3babdb29a..28945a5c7 100644 --- a/test/expect/backup-synthetic-001.log +++ b/test/expect/backup-synthetic-001.log @@ -1007,6 +1007,38 @@ incr backup - invalid path in pg_tblspc (db-master host) ERROR: [144]: pg_tblspc/path is not a symlink - pg_tblspc should contain only symlinks INFO: backup stop +incr backup - invalid relative tablespace is ../ (db-master host) +> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=detail --log-level-file=trace --log-path=[TEST_PATH]/db-master/repo/log --no-online --repo-path=[TEST_PATH]/db-master/repo --stanza=db --start-fast + INFO: last backup label = [BACKUP-FULL-2], version = [VERSION-1] + ERROR: [146]: tablespace symlink ../ destination must not be in $PGDATA + INFO: backup stop + +incr backup - invalid relative tablespace is .. (db-master host) +> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=detail --log-level-file=trace --log-path=[TEST_PATH]/db-master/repo/log --no-online --repo-path=[TEST_PATH]/db-master/repo --stanza=db --start-fast + INFO: last backup label = [BACKUP-FULL-2], version = [VERSION-1] + ERROR: [146]: tablespace symlink .. destination must not be in $PGDATA + INFO: backup stop + +incr backup - invalid relative tablespace is ../../$PGDATA (db-master host) +> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=detail --log-level-file=trace --log-path=[TEST_PATH]/db-master/repo/log --no-online --repo-path=[TEST_PATH]/db-master/repo --stanza=db --start-fast + INFO: last backup label = [BACKUP-FULL-2], version = [VERSION-1] + ERROR: [146]: tablespace symlink ../../base/ destination must not be in $PGDATA + INFO: backup stop + +incr backup - invalid relative tablespace is ../../$PGDATA (db-master host) +> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=detail --log-level-file=trace --log-path=[TEST_PATH]/db-master/repo/log --no-online --repo-path=[TEST_PATH]/db-master/repo --stanza=db --start-fast + INFO: last backup label = [BACKUP-FULL-2], version = [VERSION-1] + ERROR: [146]: tablespace symlink ../../base destination must not be in $PGDATA + INFO: backup stop + incr backup - invalid relative tablespace in $PGDATA (db-master host) > [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup ------------------------------------------------------------------------------------------------------------------------------------ @@ -1015,6 +1047,14 @@ incr backup - invalid relative tablespace in $PGDATA (db-master host) ERROR: [146]: tablespace symlink ../invalid_tblspc destination must not be in $PGDATA INFO: backup stop +incr backup - $PGDATA is a substring of valid tblspc excluding / (file open err expected) (db-master host) +> [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db-master/pgbackrest.conf --db-path=[TEST_PATH]/db-master/db/base --lock-path=[TEST_PATH]/db-master/repo/lock --log-level-console=detail --log-level-file=trace --log-path=[TEST_PATH]/db-master/repo/log --no-online --repo-path=[TEST_PATH]/db-master/repo --stanza=db --start-fast + INFO: last backup label = [BACKUP-FULL-2], version = [VERSION-1] + ERROR: [116]: unable to read [TEST_PATH]/db-master/db/base_tbs: No such file or directory + INFO: backup stop + incr backup - invalid tablespace in $PGDATA (db-master host) > [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --no-online --log-level-console=detail --stanza=db backup ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/test/lib/pgBackRestTest/Backup/BackupTest.pm b/test/lib/pgBackRestTest/Backup/BackupTest.pm index 95da21b7c..ec664e89c 100755 --- a/test/lib/pgBackRestTest/Backup/BackupTest.pm +++ b/test/lib/pgBackRestTest/Backup/BackupTest.pm @@ -1142,6 +1142,46 @@ sub backupTestRun testPathRemove("${strTblSpcPath}/path"); + # Create a relative link is PGDATA + if ($bNeutralTest && !$bRemote) + { + testLinkCreate("${strTblSpcPath}/99999", '../'); + + $oHostBackup->backup( + $strType, 'invalid relative tablespace is ../', + {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA, + strOptionalParam => '--log-level-console=detail'}); + + testFileRemove("${strTblSpcPath}/99999"); + + testLinkCreate("${strTblSpcPath}/99999", '..'); + + $oHostBackup->backup( + $strType, 'invalid relative tablespace is ..', + {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA, + strOptionalParam => '--log-level-console=detail'}); + + testFileRemove("${strTblSpcPath}/99999"); + + testLinkCreate("${strTblSpcPath}/99999", '../../base/'); + + $oHostBackup->backup( + $strType, 'invalid relative tablespace is ../../$PGDATA', + {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA, + strOptionalParam => '--log-level-console=detail'}); + + testFileRemove("${strTblSpcPath}/99999"); + + testLinkCreate("${strTblSpcPath}/99999", '../../base'); + + $oHostBackup->backup( + $strType, 'invalid relative tablespace is ../../$PGDATA', + {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA, + strOptionalParam => '--log-level-console=detail'}); + + testFileRemove("${strTblSpcPath}/99999"); + } + # Create a relative link in PGDATA testLinkCreate("${strTblSpcPath}/99999", '../invalid_tblspc'); @@ -1152,8 +1192,20 @@ sub backupTestRun testFileRemove("${strTblSpcPath}/99999"); + # Create tablespace with same initial dir name as $PGDATA + if ($bNeutralTest && !$bRemote) + { + testLinkCreate("${strTblSpcPath}/99999", $oHostDbMaster->dbBasePath() . '_tbs'); + + $oHostBackup->backup( + $strType, '$PGDATA is a substring of valid tblspc excluding / (file open err expected)', + {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_FILE_OPEN, + strOptionalParam => '--log-level-console=detail'}); + + testFileRemove("${strTblSpcPath}/99999"); + } + # Create tablespace in PGDATA - filePathCreate($oHostDbMaster->dbBasePath() . '/invalid_tblspc'); testLinkCreate("${strTblSpcPath}/99999", $oHostDbMaster->dbBasePath() . '/invalid_tblspc'); $oHostBackup->backup( @@ -1161,7 +1213,6 @@ sub backupTestRun {oExpectedManifest => \%oManifest, iExpectedExitStatus => ERROR_TABLESPACE_IN_PGDATA, strOptionalParam => '--log-level-console=detail'}); - testPathRemove($oHostDbMaster->dbBasePath() . '/invalid_tblspc'); testFileRemove("${strTblSpcPath}/99999"); # Incr backup [parent: af790be34f8c]