-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-39556 SIGSEGV in ha_mroonga::storage_set_keys_in_use on SELECT #5213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 10.6
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4287,18 +4287,15 @@ int ha_mroonga::wrapper_open(const char *name, int mode, uint open_options) | |
| if (error) | ||
| DBUG_RETURN(error); | ||
|
|
||
| if (!(open_options & HA_OPEN_FOR_REPAIR)) { | ||
| error = open_table(name); | ||
| if (error) | ||
| DBUG_RETURN(error); | ||
| error = open_table(name); | ||
| if (error && !(open_options & HA_OPEN_FOR_REPAIR)) | ||
| goto error_exit; | ||
|
|
||
| error = wrapper_open_indexes(name); | ||
| if (error) { | ||
| grn_obj_unlink(ctx, grn_table); | ||
| grn_table = NULL; | ||
| DBUG_RETURN(error); | ||
| } | ||
| } | ||
| error = wrapper_open_indexes(name); | ||
| if (error && !(open_options & HA_OPEN_FOR_REPAIR)) | ||
| goto error_exit; | ||
|
|
||
| error = 0; | ||
|
|
||
| mrn_init_alloc_root(&mem_root, 1024, 0, MYF(0)); | ||
| wrap_key_info = mrn_create_key_info_for_table(share, table, &error); | ||
|
|
@@ -4386,6 +4383,7 @@ int ha_mroonga::wrapper_open(const char *name, int mode, uint open_options) | |
| } | ||
| } | ||
|
|
||
| error_exit: | ||
| if (error) | ||
| { | ||
| grn_obj_unlink(ctx, grn_table); | ||
|
|
@@ -4658,37 +4656,35 @@ int ha_mroonga::storage_open(const char *name, int mode, uint open_options) | |
| DBUG_RETURN(error); | ||
| } | ||
|
|
||
| if (!(open_options & HA_OPEN_FOR_REPAIR)) { | ||
| error = storage_open_indexes(name); | ||
| if (error) { | ||
| storage_close_columns(); | ||
| grn_obj_unlink(ctx, grn_table); | ||
| grn_table = NULL; | ||
| DBUG_RETURN(error); | ||
| } | ||
| error = storage_open_indexes(name); | ||
| if (error && !(open_options & HA_OPEN_FOR_REPAIR)) { | ||
| storage_close_columns(); | ||
| grn_obj_unlink(ctx, grn_table); | ||
| grn_table = NULL; | ||
| DBUG_RETURN(error); | ||
| } | ||
|
Comment on lines
+4659
to
+4665
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If We should reset error = storage_open_indexes(name);
if (error) {
if (!(open_options & HA_OPEN_FOR_REPAIR)) {
storage_close_columns();
grn_obj_unlink(ctx, grn_table);
grn_table = NULL;
DBUG_RETURN(error);
}
error = 0;
} |
||
|
|
||
| storage_set_keys_in_use(); | ||
| storage_set_keys_in_use(); | ||
|
|
||
| { | ||
| mrn::Lock lock(&mrn_operations_mutex); | ||
| mrn::PathMapper mapper(name); | ||
| const char *table_name = mapper.table_name(); | ||
| size_t table_name_size = strlen(table_name); | ||
| if (db->is_broken_table(table_name, table_name_size)) { | ||
| GRN_LOG(ctx, GRN_LOG_NOTICE, | ||
| "Auto repair is started: <%s>", | ||
| name); | ||
| error = operations_->repair(table_name, table_name_size); | ||
| if (!(open_options & HA_OPEN_FOR_REPAIR)) { | ||
| mrn::Lock lock(&mrn_operations_mutex); | ||
| mrn::PathMapper mapper(name); | ||
| const char *table_name = mapper.table_name(); | ||
| size_t table_name_size = strlen(table_name); | ||
| if (db->is_broken_table(table_name, table_name_size)) { | ||
| GRN_LOG(ctx, GRN_LOG_NOTICE, | ||
| "Auto repair is started: <%s>", | ||
| name); | ||
| error = operations_->repair(table_name, table_name_size); | ||
| if (!error) | ||
| db->mark_table_repaired(table_name, table_name_size); | ||
| if (!share->disable_keys) { | ||
| if (!error) | ||
| db->mark_table_repaired(table_name, table_name_size); | ||
| if (!share->disable_keys) { | ||
| if (!error) | ||
| error = storage_reindex(); | ||
| } | ||
| GRN_LOG(ctx, GRN_LOG_NOTICE, | ||
| "Auto repair is done: <%s>: %s", | ||
| name, error == 0 ? "success" : "failure"); | ||
| error = storage_reindex(); | ||
| } | ||
| GRN_LOG(ctx, GRN_LOG_NOTICE, | ||
| "Auto repair is done: <%s>: %s", | ||
| name, error == 0 ? "success" : "failure"); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -5233,7 +5229,7 @@ void ha_mroonga::storage_set_keys_in_use() | |
| if (i == table_share->primary_key) { | ||
| continue; | ||
| } | ||
| if (!grn_index_tables[i]) { | ||
| if (grn_index_tables && !grn_index_tables[i]) { | ||
| /* disabled */ | ||
| table_share->keys_in_use.clear_bit(i); | ||
| DBUG_PRINT("info", ("mroonga: key %u disabled", i)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # | ||
| # MDEV-39556 SIGSEGV in ha_mroonga::storage_set_keys_in_use on SELECT | ||
| # | ||
| CREATE TABLE t (c INT KEY,c2 GEOMETRY NOT NULL,SPATIAL INDEX idx_sp (c2)) ENGINE=InnoDB; | ||
| ALTER TABLE t ENGINE=Mroonga; | ||
| CHECK TABLE t; | ||
| Table Op Msg_type Msg_text | ||
| test.t check status OK | ||
| SELECT COUNT(*) > 0 AS r FROM information_schema.STATISTICS; | ||
| r | ||
| 1 | ||
| DROP TABLE t; | ||
| # End of 10.6 tests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --source include/have_innodb.inc | ||
|
|
||
| --echo # | ||
| --echo # MDEV-39556 SIGSEGV in ha_mroonga::storage_set_keys_in_use on SELECT | ||
| --echo # | ||
|
|
||
| CREATE TABLE t (c INT KEY,c2 GEOMETRY NOT NULL,SPATIAL INDEX idx_sp (c2)) ENGINE=InnoDB; | ||
|
|
||
| ALTER TABLE t ENGINE=Mroonga; | ||
| CHECK TABLE t; | ||
| SELECT COUNT(*) > 0 AS r FROM information_schema.STATISTICS; | ||
|
|
||
| DROP TABLE t; | ||
|
|
||
| --echo # End of 10.6 tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
open_table(name)fails andHA_OPEN_FOR_REPAIRis set,errorwill be non-zero, but the execution will continue instead of jumping toerror_exit. In this scenario, callingwrapper_open_indexes(name)is unsafe because the table was not successfully opened (meaninggrn_tableis likelyNULLor invalid), which can lead to a crash (segmentation fault) insidewrapper_open_indexes.We should only attempt to open the indexes if
open_tablesucceeded. Ifopen_tablefailed butHA_OPEN_FOR_REPAIRis set, we should skip opening the indexes and proceed.