fix: do not access optionInfo unless the option already exists in the map

This commit is contained in:
Evan Tschannen 2019-07-10 18:48:54 -07:00
parent 7e919e361c
commit bbef631872
5 changed files with 29 additions and 5 deletions

View File

@ -596,9 +596,14 @@ Version MultiVersionTransaction::getCommittedVersion() {
}
void MultiVersionTransaction::setOption(FDBTransactionOptions::Option option, Optional<StringRef> value) {
if(MultiVersionApi::apiVersionAtLeast(610) && FDBTransactionOptions::optionInfo[option].persistent) {
auto itr = FDBTransactionOptions::optionInfo.find(option);
if(itr == FDBTransactionOptions::optionInfo.end()) {
TraceEvent("UnknownTransactionOption").detail("Option", option);
throw invalid_option();
}
if(MultiVersionApi::apiVersionAtLeast(610) && itr->second.persistent) {
persistentOptions.emplace_back(option, value.castTo<Standalone<StringRef>>());
}
auto tr = getTransaction();
if(tr.transaction) {
@ -683,7 +688,7 @@ void MultiVersionDatabase::setOption(FDBDatabaseOptions::Option option, Optional
throw invalid_option();
}
int defaultFor = FDBDatabaseOptions::optionInfo[option].defaultFor;
int defaultFor = itr->second.defaultFor;
if (defaultFor >= 0) {
ASSERT(FDBTransactionOptions::optionInfo.find((FDBTransactionOptions::Option)defaultFor) !=
FDBTransactionOptions::optionInfo.end());

View File

@ -756,7 +756,13 @@ uint64_t extractHexOption( StringRef value ) {
}
void DatabaseContext::setOption( FDBDatabaseOptions::Option option, Optional<StringRef> value) {
int defaultFor = FDBDatabaseOptions::optionInfo[option].defaultFor;
auto itr = FDBDatabaseOptions::optionInfo.find(option);
if(itr == FDBDatabaseOptions::optionInfo.end()) {
TraceEvent("UnknownDatabaseOption").detail("Option", option);
throw invalid_option();
}
int defaultFor = itr->second.defaultFor;
if (defaultFor >= 0) {
ASSERT(FDBTransactionOptions::optionInfo.find((FDBTransactionOptions::Option)defaultFor) !=
FDBTransactionOptions::optionInfo.end());

View File

@ -1759,9 +1759,15 @@ Future<Standalone<StringRef>> ReadYourWritesTransaction::getVersionstamp() {
}
void ReadYourWritesTransaction::setOption( FDBTransactionOptions::Option option, Optional<StringRef> value ) {
auto itr = FDBTransactionOptions::optionInfo.find(option);
if(itr == FDBTransactionOptions::optionInfo.end()) {
TraceEvent("UnknownTransactionOption").detail("Option", option);
throw invalid_option();
}
setOptionImpl(option, value);
if(FDBTransactionOptions::optionInfo[option].persistent) {
if(itr->second.persistent) {
persistentOptions.emplace_back(option, value.castTo<Standalone<StringRef>>());
}

View File

@ -283,6 +283,12 @@ ThreadFuture<Standalone<StringRef>> ThreadSafeTransaction::getVersionstamp() {
}
void ThreadSafeTransaction::setOption( FDBTransactionOptions::Option option, Optional<StringRef> value ) {
auto itr = FDBTransactionOptions::optionInfo.find(option);
if(itr == FDBTransactionOptions::optionInfo.end()) {
TraceEvent("UnknownTransactionOption").detail("Option", option);
throw invalid_option();
}
ReadYourWritesTransaction *tr = this->tr;
Standalone<Optional<StringRef>> passValue = value;

View File

@ -1092,6 +1092,7 @@ struct FuzzApiCorrectnessWorkload : TestWorkload {
}
contract = {
std::make_pair( error_code_invalid_option, ExceptionContract::Possible ),
std::make_pair( error_code_invalid_option_value, ExceptionContract::Possible ),
std::make_pair( error_code_client_invalid_operation, ExceptionContract::possibleIf((FDBTransactionOptions::Option)op == FDBTransactionOptions::READ_YOUR_WRITES_DISABLE ||
(FDBTransactionOptions::Option)op == FDBTransactionOptions::LOG_TRANSACTION) ),