#At file:///C:/source/bzr/mysql-6.0-bug-42695/ based on revid:charles.bell@stripped
2780 Chuck Bell 2009-02-25
BUG#42695 : memory leak when setting backupdir
BUG#42685 : valgrind errors setting backup_progress_log_file
The patch for these bugs both use the new error message and in many
ways similar so thus the combined patch.
This patch adds code to detect when users attempt to set a path
longer than FN_REFLEN.
For BUG#42695, the patch also frees memory used when a successful
update to the backupdir variable is completed.
modified:
mysql-test/suite/backup/r/backup_backupdir.result
mysql-test/suite/backup/r/backup_logs.result
mysql-test/suite/backup/t/backup_backupdir.test
mysql-test/suite/backup/t/backup_logs.test
sql/set_var.cc
sql/share/errmsg.txt
per-file messages:
mysql-test/suite/backup/r/backup_backupdir.result
Corrected result file.
mysql-test/suite/backup/r/backup_logs.result
Corrected result file.
mysql-test/suite/backup/t/backup_backupdir.test
Added test to check for exceeding maximum path length.
mysql-test/suite/backup/t/backup_logs.test
Added test to check for exceeding maximum path length.
sql/set_var.cc
Added code to ensure users do not attempt to assign a path longer
than FN_REFLEN.
Added code to free the memory used on update for backupdir.
sql/share/errmsg.txt
New error message for exceeding maximum path length.
=== modified file 'mysql-test/suite/backup/r/backup_backupdir.result'
--- a/mysql-test/suite/backup/r/backup_backupdir.result 2008-12-24 10:48:24 +0000
+++ b/mysql-test/suite/backup/r/backup_backupdir.result 2009-02-25 19:58:57 +0000
@@ -50,11 +50,17 @@ Try a backup to an invalid hard path.
*BACKUP DATABASE bup_backupdir TO '$MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak';
ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master_data/not/there/either/bup_backupdir6.bak' (Errcode: #)
+Attempt to set the backupdir to a really long string.
+set global max_allowed_packet=1024*100;
+SET @@global.backupdir = repeat('a',99*1024);
+ERROR HY000: The path specified is too long.
+
Attempt to set the backupdir to something invalid.
SET @@global.backupdir = 'This_is_really_stupid/not/there/at/all';
Warnings:
Warning 1733 The path specified for the system variable backupdir cannot be accessed or is invalid. ref: This_is_really_stupid/not/there/at/all
Warning 1733 The path specified for the system variable backupdir cannot be accessed or is invalid. ref: This_is_really_stupid/not/there/at/all
+set global max_allowed_packet=DEFAULT;
Cleanup
Reset backupdir
SET @@global.backupdir = @@global.datadir;
=== modified file 'mysql-test/suite/backup/r/backup_logs.result'
--- a/mysql-test/suite/backup/r/backup_logs.result 2009-02-20 16:40:19 +0000
+++ b/mysql-test/suite/backup/r/backup_logs.result 2009-02-25 19:58:57 +0000
@@ -362,6 +362,16 @@ The backup id for this command should be
BACKUP DATABASE backup_logs to 'backup_logs_orig.bak';
backup_id
505
+
+Attempt to set the backup log paths to a really long string.
+set global max_allowed_packet=1024*100;
+SET @@global.backup_progress_log_file = repeat('a',99*1024);
+ERROR HY000: The path specified is too long.
+set @@global.backup_progress_log_file = DEFAULT;
+SET @@global.backup_history_log_file = repeat('a',99*1024);
+ERROR HY000: The path specified is too long.
+set @@global.backup_history_log_file = DEFAULT;
+set global max_allowed_packet=DEFAULT;
SET @@global.log_backup_output = 'TABLE';
DROP USER 'tom'@'localhost';
SET DEBUG_SYNC= 'reset';
=== modified file 'mysql-test/suite/backup/t/backup_backupdir.test'
--- a/mysql-test/suite/backup/t/backup_backupdir.test 2008-12-24 10:48:24 +0000
+++ b/mysql-test/suite/backup/t/backup_backupdir.test 2009-02-25 19:58:57 +0000
@@ -103,9 +103,19 @@ BACKUP DATABASE bup_backupdir TO '../not
--enable_query_log
--echo
+--echo Attempt to set the backupdir to a really long string.
+
+set global max_allowed_packet=1024*100;
+
+--error ER_PATH_LENGTH
+SET @@global.backupdir = repeat('a',99*1024);
+
+--echo
--echo Attempt to set the backupdir to something invalid.
SET @@global.backupdir = 'This_is_really_stupid/not/there/at/all';
+set global max_allowed_packet=DEFAULT;
+
--echo Cleanup
--echo Reset backupdir
=== modified file 'mysql-test/suite/backup/t/backup_logs.test'
--- a/mysql-test/suite/backup/t/backup_logs.test 2009-02-20 16:40:19 +0000
+++ b/mysql-test/suite/backup/t/backup_logs.test 2009-02-25 19:58:57 +0000
@@ -471,6 +471,22 @@ BACKUP DATABASE backup_logs to 'backup_l
# Cleanup.
#
+--echo
+--echo Attempt to set the backup log paths to a really long string.
+
+set global max_allowed_packet=1024*100;
+
+--error ER_PATH_LENGTH
+SET @@global.backup_progress_log_file = repeat('a',99*1024);
+set @@global.backup_progress_log_file = DEFAULT;
+
+--error ER_PATH_LENGTH
+SET @@global.backup_history_log_file = repeat('a',99*1024);
+set @@global.backup_history_log_file = DEFAULT;
+
+set global max_allowed_packet=DEFAULT;
+
+
SET @@global.log_backup_output = 'TABLE';
DROP USER 'tom'@'localhost';
SET DEBUG_SYNC= 'reset';
=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc 2009-02-20 16:40:19 +0000
+++ b/sql/set_var.cc 2009-02-25 19:58:57 +0000
@@ -2528,6 +2528,16 @@ static int sys_check_log_path(THD *thd,
if (!(res= var->value->val_str(&str)))
goto err;
+ /*
+ Check maximum string length and error if too long.
+ Do not set the value.
+ */
+ if (res->length() > FN_REFLEN)
+ {
+ my_error(ER_PATH_LENGTH, MYF(0), ER(ER_PATH_LENGTH));
+ return 1;
+ }
+
log_file_str= res->c_ptr();
bzero(&f_stat, sizeof(MY_STAT));
@@ -3002,6 +3012,16 @@ static bool sys_update_backupdir(THD *th
str_length= strlen(old_value);
}
+ /*
+ Check maximum string length and error if too long.
+ Do not set the value.
+ */
+ if (str_length > FN_REFLEN)
+ {
+ my_error(ER_PATH_LENGTH, MYF(0), ER(ER_PATH_LENGTH));
+ return 1;
+ }
+
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
{
result= 1;
@@ -3010,7 +3030,7 @@ static bool sys_update_backupdir(THD *th
pthread_mutex_lock(&LOCK_global_system_variables);
logger.lock_exclusive();
- old_value= sys_var_backupdir.value;
+ my_free(sys_var_backupdir.value, MYF(MY_ALLOW_ZERO_PTR));
sys_var_backupdir.value= res;
sys_var_backupdir.value_length= str_length;
logger.unlock();
=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt 2009-02-12 17:56:03 +0000
+++ b/sql/share/errmsg.txt 2009-02-25 19:58:57 +0000
@@ -6463,4 +6463,5 @@ ER_OPERATION_ABORTED
eng "Operation aborted"
ER_OPERATION_ABORTED_CORRUPTED
eng "Operation aborted - data might be corrupted"
-
+ER_PATH_LENGTH
+ eng "The path specified is too long."