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