null+****@clear*****
null+****@clear*****
2012年 6月 24日 (日) 19:01:04 JST
Kouhei Sutou 2012-06-24 19:01:04 +0900 (Sun, 24 Jun 2012) New Revision: 1b22053fd2f5b3924188bd55716dd46d8f16b8e4 https://github.com/mroonga/mroonga/commit/1b22053fd2f5b3924188bd55716dd46d8f16b8e4 Log: Fix a crash bug by setting nonexistent path to mroonga_log_file variable fixes #1404 Reported by @nabebeb. Thanks!!! Added files: test/sql/suite/mroonga_storage/r/log_file.result test/sql/suite/mroonga_storage/t/log_file.test Modified files: ha_mroonga.cpp Modified: ha_mroonga.cpp (+30 -15) =================================================================== --- ha_mroonga.cpp 2012-06-11 16:39:41 +0900 (87fd373) +++ ha_mroonga.cpp 2012-06-24 19:01:04 +0900 (09ef35d) @@ -654,28 +654,43 @@ static void mrn_log_file_update(THD *thd, struct st_mysql_sys_var *var, "because the requested path isn't different: <%s>", new_value); } else { - char *old_value; - - old_value = strdup(*old_value_ptr); GRN_LOG(&ctx, GRN_LOG_NOTICE, "log file is changed: <%s> -> <%s>", - old_value, new_value); - - my_free(*old_value_ptr, MYF(0)); - *old_value_ptr = my_strdup(new_value, MYF(MY_WME)); + *old_value_ptr, new_value); pthread_mutex_lock(&mrn_log_mutex); - if (mrn_log_file_opened) { - fclose(mrn_log_file); + FILE *new_log_file; + int log_file_open_errno = 0; + new_log_file = fopen(new_value, "a"); + if (new_log_file) { + if (mrn_log_file_opened) { + fclose(mrn_log_file); + } + mrn_log_file = new_log_file; + mrn_log_file_opened = true; + } else { + log_file_open_errno = errno; } - mrn_log_file = fopen(new_value, "a"); - mrn_log_file_opened = true; pthread_mutex_unlock(&mrn_log_mutex); - GRN_LOG(&ctx, GRN_LOG_NOTICE, - "log file is changed: <%s> -> <%s>", - old_value, new_value); - free(old_value); + if (log_file_open_errno == 0) { + GRN_LOG(&ctx, GRN_LOG_NOTICE, + "log file is changed: <%s> -> <%s>", + *old_value_ptr, new_value); + *old_value_ptr = my_strdup(new_value, MYF(MY_WME)); + } else { + if (mrn_log_file) { + GRN_LOG(&ctx, GRN_LOG_ERROR, + "log file isn't changed " + "because the requested path can't be opened: <%s>: <%s>", + new_value, strerror(log_file_open_errno)); + } else { + GRN_LOG(&ctx, GRN_LOG_ERROR, + "log file can't be opened: <%s>: <%s>", + new_value, strerror(log_file_open_errno)); + } + *old_value_ptr = my_strdup(*old_value_ptr, MYF(MY_WME)); + } } grn_ctx_fin(&ctx); Added: test/sql/suite/mroonga_storage/r/log_file.result (+8 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/r/log_file.result 2012-06-24 19:01:04 +0900 (e801c59) @@ -0,0 +1,8 @@ +SET GLOBAL mroonga_log_file = "new-mroonga.log"; +SHOW GLOBAL VARIABLES LIKE 'mroonga_log_file'; +Variable_name Value +mroonga_log_file new-mroonga.log +SET GLOBAL mroonga_log_file = "nonexistent/mroonga.log"; +SHOW GLOBAL VARIABLES LIKE 'mroonga_log_file'; +Variable_name Value +mroonga_log_file new-mroonga.log Added: test/sql/suite/mroonga_storage/t/log_file.test (+25 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/t/log_file.test 2012-06-24 19:01:04 +0900 (180ff66) @@ -0,0 +1,25 @@ +# Copyright(C) 2012 Kouhei Sutou <kou****@clear*****> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source include/have_mroonga.inc + +SET GLOBAL mroonga_log_file = "new-mroonga.log"; +SHOW GLOBAL VARIABLES LIKE 'mroonga_log_file'; + +SET GLOBAL mroonga_log_file = "nonexistent/mroonga.log"; +SHOW GLOBAL VARIABLES LIKE 'mroonga_log_file'; + +--source include/have_mroonga_deinit.inc -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download