PDA

View Full Version : mysql-zrm-restore does not check for running out of disk space



orion
March 19th, 2014, 01:56 PM
In extractToTmpFile(), there are no checks if the writes to the temp file succeeds or not. It will happily continue trying to restore from a truncated file if the tmpdir is not large enough to hold the file. It needs to abort on errors.

orion
March 19th, 2014, 02:17 PM
diff -up MySQL-zrm-3.0/usr/bin/mysql-zrm-restore.tmpwrite MySQL-zrm-3.0/usr/bin/mysql-zrm-restore
--- MySQL-zrm-3.0/usr/bin/mysql-zrm-restore.tmpwrite 2013-08-26 14:45:36.000000000 -0600
+++ MySQL-zrm-3.0/usr/bin/mysql-zrm-restore 2014-03-19 16:13:17.360910775 -0600
@@ -415,7 +415,7 @@ sub extractToTmpFile()
$dbs =~s/\s/|/g;
open( MSQL, $sqlmaster ) or &printAndDie( "Could not open file $sqlmaster $!\n" );
my $tf = tmpnam();
- open(OF,">$tf" ) or &printAndDie( "Coupld not open tmp file $tf $!\n" );
+ open(OF,">$tf" ) or &printAndDie( "Could not open tmp file $tf $!\n" );
my $found = 0;
while(<MSQL>){
if( /^-- Current Database: / ){
@@ -425,10 +425,18 @@ sub extractToTmpFile()
$found = /\`($dbs)\`/ ? 1:0;
}
if( $found ){
- print OF $_;
+ if ( ! print OF $_ ) {
+ my $r = "$!";
+ unlink( $tf );
+ &printAndDie( "Could not write to tmp file $tf $r\n" );
+ }
}elsif( /^\/\*\!\d*\s*SET / ){
# Also print if statement is "/*! SET "
- print OF $_;
+ if ( ! print OF $_ ) {
+ my $r = "$!";
+ unlink( $tf );
+ &printAndDie( "Could not write to tmp file $tf $r\n" );
+ }
}
}
close( OF );