Skip to content

Commit

Permalink
[WASimClient] Validate that variable type is settable before sending …
Browse files Browse the repository at this point in the history
…command to server.
  • Loading branch information
mpaperno committed Nov 6, 2023
1 parent 9482348 commit 576914a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/WASimClient/WASimClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,10 +952,14 @@ class WASimClient::Private

HRESULT setVariable(const VariableRequest &v, const double value)
{
const string sValue = buildVariableCommandString(v, true);
if (sValue.empty() || sValue.length() >= STRSZ_CMD)
return E_INVALIDARG;
return sendServerCommand(Command(v.createLVar && v.variableType == 'L' ? CommandId::SetCreate : CommandId::Set, v.variableType, sValue.c_str(), value));
if (Utilities::isSettableVariableType(v.variableType)) {
const string sValue = buildVariableCommandString(v, true);
if (sValue.empty() || sValue.length() >= STRSZ_CMD)
return E_INVALIDARG;
return sendServerCommand(Command(v.createLVar && v.variableType == 'L' ? CommandId::SetCreate : CommandId::Set, v.variableType, sValue.c_str(), value));
}
LOG_WRN << "Cannot Set a variable of type '" << v.variableType << "'.";
return E_INVALIDARG;
}

#pragma endregion
Expand Down
5 changes: 5 additions & 0 deletions src/shared/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ namespace WASimCommander {
return find(VAR_TYPES_UNIT_BASED.cbegin(), VAR_TYPES_UNIT_BASED.cend(), type) != VAR_TYPES_UNIT_BASED.cend();
}

static bool isSettableVariableType(const char type) {
static const std::vector<char> VAR_TYPES_SETTABLE = { 'A', 'C', 'H', 'K', 'L', 'Z' };
return find(VAR_TYPES_SETTABLE.cbegin(), VAR_TYPES_SETTABLE.cend(), type) != VAR_TYPES_SETTABLE.cend();
}

// returns actual byte size from given size which may be one of the SimConnect_AddToClientDataDefinition() dwSizeOrType constants
static constexpr uint32_t getActualValueSize(DWORD dwSizeOrType)
{
Expand Down

0 comments on commit 576914a

Please sign in to comment.