Skip to content

Commit

Permalink
Fix cf_option if parse_cf_option fail
Browse files Browse the repository at this point in the history
Summary: Seems my previous fix missed one case. If the cf_parse_option fails, we may leave a dangling ptr. Changing the code a little bit to avoid this.

Reviewed By: lth

Differential Revision: D15880761

fbshipit-source-id: 84edc55
  • Loading branch information
zhichengzhu authored and facebook-github-bot committed Dec 23, 2019
1 parent 2f6a656 commit 4cd8178
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13640,12 +13640,8 @@ static int rocksdb_validate_update_cf_options(
int length;
length = sizeof(buff);
str = value->val_str(value, buff, &length);
// In some cases, str can point to buff in the stack.
// This can cause invalid memory access after validation is finished.
// To avoid this kind case, let's alway duplicate the str if str is not
// nullptr
*(const char **)save = (str == nullptr) ? nullptr : my_strdup(str, MYF(0));

*(const char **)save = nullptr;
if (str == nullptr) {
return HA_EXIT_SUCCESS;
}
Expand All @@ -13658,11 +13654,18 @@ static int rocksdb_validate_update_cf_options(
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "rocksdb_update_cf_options", str);
return HA_EXIT_FAILURE;
}

// Loop through option_map and create missing column families
for (Rdb_cf_options::Name_to_config_t::iterator it = option_map.begin();
it != option_map.end(); ++it) {
cf_manager.get_or_create_cf(rdb, it->first);
}

// In some cases, str can point to buff in the stack.
// This can cause invalid memory access after validation is finished.
// To avoid this kind case, let's alway duplicate the str.
*(const char **)save = my_strdup(str, MYF(0));

return HA_EXIT_SUCCESS;
}

Expand Down

0 comments on commit 4cd8178

Please sign in to comment.