@@ -942,31 +942,30 @@ static void moveHandler(app::CommandHandler * commandObj, const app::ConcreteCom
942
942
app::DataModel::Nullable<uint8_t > rate, chip::Optional<BitMask<OptionsBitmap>> optionsMask,
943
943
chip::Optional<BitMask<OptionsBitmap>> optionsOverride)
944
944
{
945
- EndpointId endpoint = commandPath.mEndpointId ;
946
- CommandId commandId = commandPath.mCommandId ;
947
-
948
- EmberAfLevelControlState * state = getState (endpoint);
949
945
Status status;
950
- app::DataModel::Nullable<uint8_t > currentLevel;
951
946
uint8_t difference;
947
+ EmberAfLevelControlState * state;
948
+ app::DataModel::Nullable<uint8_t > currentLevel;
952
949
953
- if (state == nullptr )
950
+ EndpointId endpoint = commandPath.mEndpointId ;
951
+ CommandId commandId = commandPath.mCommandId ;
952
+ // Validate the received rate and moveMode first.
953
+ if ((!rate.IsNull () && (rate.Value () == 0 )) || moveMode == MoveModeEnum::kUnknownEnumValue )
954
954
{
955
- status = Status::Failure ;
955
+ status = Status::InvalidCommand ;
956
956
goto send_default_response;
957
957
}
958
958
959
- if (!shouldExecuteIfOff (endpoint, commandId, optionsMask, optionsOverride))
959
+ state = getState (endpoint);
960
+ if (state == nullptr )
960
961
{
961
- status = Status::Success ;
962
+ status = Status::Failure ;
962
963
goto send_default_response;
963
964
}
964
965
965
- // Always validate the rate parameter received. A rate of 0 is invalid.
966
- if (!rate.IsNull () && (rate.Value () == 0 ))
966
+ if (!shouldExecuteIfOff (endpoint, commandId, optionsMask, optionsOverride))
967
967
{
968
- // Providing rate of 0 is not allowed.
969
- status = Status::InvalidCommand;
968
+ status = Status::Success;
970
969
goto send_default_response;
971
970
}
972
971
@@ -1084,14 +1083,22 @@ static void stepHandler(app::CommandHandler * commandObj, const app::ConcreteCom
1084
1083
uint8_t stepSize, app::DataModel::Nullable<uint16_t > transitionTimeDs,
1085
1084
chip::Optional<BitMask<OptionsBitmap>> optionsMask, chip::Optional<BitMask<OptionsBitmap>> optionsOverride)
1086
1085
{
1087
- EndpointId endpoint = commandPath.mEndpointId ;
1088
- CommandId commandId = commandPath.mCommandId ;
1089
-
1090
- EmberAfLevelControlState * state = getState (endpoint);
1091
1086
Status status;
1087
+ EmberAfLevelControlState * state;
1092
1088
app::DataModel::Nullable<uint8_t > currentLevel;
1089
+
1090
+ EndpointId endpoint = commandPath.mEndpointId ;
1091
+ CommandId commandId = commandPath.mCommandId ;
1093
1092
uint8_t actualStepSize = stepSize;
1094
1093
1094
+ // Validate the received stepSize and stepMode first.
1095
+ if (stepSize == 0 || stepMode == StepModeEnum::kUnknownEnumValue )
1096
+ {
1097
+ status = Status::InvalidCommand;
1098
+ goto send_default_response;
1099
+ }
1100
+
1101
+ state = getState (endpoint);
1095
1102
if (state == nullptr )
1096
1103
{
1097
1104
status = Status::Failure;
@@ -1153,6 +1160,7 @@ static void stepHandler(app::CommandHandler * commandObj, const app::ConcreteCom
1153
1160
}
1154
1161
break ;
1155
1162
default :
1163
+ // Should never happen as it is verified at function entry.
1156
1164
status = Status::InvalidCommand;
1157
1165
goto send_default_response;
1158
1166
}
0 commit comments