@@ -950,31 +950,30 @@ static void moveHandler(app::CommandHandler * commandObj, const app::ConcreteCom
950
950
app::DataModel::Nullable<uint8_t > rate, chip::Optional<BitMask<OptionsBitmap>> optionsMask,
951
951
chip::Optional<BitMask<OptionsBitmap>> optionsOverride)
952
952
{
953
- EndpointId endpoint = commandPath.mEndpointId ;
954
- CommandId commandId = commandPath.mCommandId ;
955
-
956
- EmberAfLevelControlState * state = getState (endpoint);
957
953
Status status;
958
- app::DataModel::Nullable<uint8_t > currentLevel;
959
954
uint8_t difference;
955
+ EmberAfLevelControlState * state;
956
+ app::DataModel::Nullable<uint8_t > currentLevel;
960
957
961
- if (state == nullptr )
958
+ EndpointId endpoint = commandPath.mEndpointId ;
959
+ CommandId commandId = commandPath.mCommandId ;
960
+ // Validate the received rate and moveMode first.
961
+ if ((!rate.IsNull () && (rate.Value () == 0 )) || moveMode == MoveModeEnum::kUnknownEnumValue )
962
962
{
963
- status = Status::Failure ;
963
+ status = Status::InvalidCommand ;
964
964
goto send_default_response;
965
965
}
966
966
967
- if (!shouldExecuteIfOff (endpoint, commandId, optionsMask, optionsOverride))
967
+ state = getState (endpoint);
968
+ if (state == nullptr )
968
969
{
969
- status = Status::Success ;
970
+ status = Status::Failure ;
970
971
goto send_default_response;
971
972
}
972
973
973
- // Always validate the rate parameter received. A rate of 0 is invalid.
974
- if (!rate.IsNull () && (rate.Value () == 0 ))
974
+ if (!shouldExecuteIfOff (endpoint, commandId, optionsMask, optionsOverride))
975
975
{
976
- // Providing rate of 0 is not allowed.
977
- status = Status::InvalidCommand;
976
+ status = Status::Success;
978
977
goto send_default_response;
979
978
}
980
979
@@ -1092,14 +1091,22 @@ static void stepHandler(app::CommandHandler * commandObj, const app::ConcreteCom
1092
1091
uint8_t stepSize, app::DataModel::Nullable<uint16_t > transitionTimeDs,
1093
1092
chip::Optional<BitMask<OptionsBitmap>> optionsMask, chip::Optional<BitMask<OptionsBitmap>> optionsOverride)
1094
1093
{
1095
- EndpointId endpoint = commandPath.mEndpointId ;
1096
- CommandId commandId = commandPath.mCommandId ;
1097
-
1098
- EmberAfLevelControlState * state = getState (endpoint);
1099
1094
Status status;
1095
+ EmberAfLevelControlState * state;
1100
1096
app::DataModel::Nullable<uint8_t > currentLevel;
1097
+
1098
+ EndpointId endpoint = commandPath.mEndpointId ;
1099
+ CommandId commandId = commandPath.mCommandId ;
1101
1100
uint8_t actualStepSize = stepSize;
1102
1101
1102
+ // Validate the received stepSize and stepMode first.
1103
+ if (stepSize == 0 || stepMode == StepModeEnum::kUnknownEnumValue )
1104
+ {
1105
+ status = Status::InvalidCommand;
1106
+ goto send_default_response;
1107
+ }
1108
+
1109
+ state = getState (endpoint);
1103
1110
if (state == nullptr )
1104
1111
{
1105
1112
status = Status::Failure;
@@ -1161,6 +1168,7 @@ static void stepHandler(app::CommandHandler * commandObj, const app::ConcreteCom
1161
1168
}
1162
1169
break ;
1163
1170
default :
1171
+ // Should never happen as it is verified at function entry.
1164
1172
status = Status::InvalidCommand;
1165
1173
goto send_default_response;
1166
1174
}
0 commit comments