Skip to content

Commit 144bfec

Browse files
[Scenes] ScenesID Constraints Check (#34600)
* Added check for SceneID outside out of bounds and yaml tests * Restyled by whitespace --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 725f7ac commit 144bfec

File tree

2 files changed

+155
-7
lines changed

2 files changed

+155
-7
lines changed

src/app/clusters/scenes-server/scenes-server.cpp

+43-2
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@ void AddSceneParse(CommandHandlerInterface::HandlerContext & ctx, const CommandD
376376
response.sceneID = req.sceneID;
377377

378378
// Verify the attributes are respecting constraints
379-
if (req.transitionTime > scenes::kScenesMaxTransitionTime || req.sceneName.size() > scenes::kSceneNameMaxLength)
379+
if (req.transitionTime > scenes::kScenesMaxTransitionTime || req.sceneName.size() > scenes::kSceneNameMaxLength ||
380+
req.sceneID == scenes::kUndefinedSceneId)
380381
{
381-
response.status = to_underlying(Protocols::InteractionModel::Status::InvalidCommand);
382+
response.status = to_underlying(Protocols::InteractionModel::Status::ConstraintError);
382383
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
383384
return;
384385
}
@@ -483,6 +484,14 @@ void ViewSceneParse(HandlerContext & ctx, const CommandData & req, GroupDataProv
483484
response.groupID = req.groupID;
484485
response.sceneID = req.sceneID;
485486

487+
// Verify the attributes are respecting constraints
488+
if (req.sceneID == scenes::kUndefinedSceneId)
489+
{
490+
response.status = to_underlying(Protocols::InteractionModel::Status::ConstraintError);
491+
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
492+
return;
493+
}
494+
486495
// Verify Endpoint in group
487496
VerifyOrReturn(nullptr != groupProvider);
488497
if (0 != req.groupID &&
@@ -830,6 +839,14 @@ void ScenesServer::HandleRemoveScene(HandlerContext & ctx, const Commands::Remov
830839
response.groupID = req.groupID;
831840
response.sceneID = req.sceneID;
832841

842+
// Verify the attributes are respecting constraints
843+
if (req.sceneID == scenes::kUndefinedSceneId)
844+
{
845+
response.status = to_underlying(Protocols::InteractionModel::Status::ConstraintError);
846+
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
847+
return;
848+
}
849+
833850
// Scene Table interface data
834851
SceneTableEntry scene(SceneStorageId(req.sceneID, req.groupID));
835852

@@ -930,6 +947,14 @@ void ScenesServer::HandleStoreScene(HandlerContext & ctx, const Commands::StoreS
930947
response.groupID = req.groupID;
931948
response.sceneID = req.sceneID;
932949

950+
// Verify the attributes are respecting constraints
951+
if (req.sceneID == scenes::kUndefinedSceneId)
952+
{
953+
response.status = to_underlying(Protocols::InteractionModel::Status::ConstraintError);
954+
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
955+
return;
956+
}
957+
933958
CHIP_ERROR err = StoreSceneParse(ctx.mCommandHandler.GetAccessingFabricIndex(), ctx.mRequestPath.mEndpointId, req.groupID,
934959
req.sceneID, mGroupProvider);
935960

@@ -943,6 +968,14 @@ void ScenesServer::HandleStoreScene(HandlerContext & ctx, const Commands::StoreS
943968
void ScenesServer::HandleRecallScene(HandlerContext & ctx, const Commands::RecallScene::DecodableType & req)
944969
{
945970
MATTER_TRACE_SCOPE("RecallScene", "Scenes");
971+
972+
// Verify the attributes are respecting constraints
973+
if (req.sceneID == scenes::kUndefinedSceneId)
974+
{
975+
ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::ConstraintError);
976+
return;
977+
}
978+
946979
CHIP_ERROR err = RecallSceneParse(ctx.mCommandHandler.GetAccessingFabricIndex(), ctx.mRequestPath.mEndpointId, req.groupID,
947980
req.sceneID, req.transitionTime, mGroupProvider);
948981

@@ -1025,6 +1058,14 @@ void ScenesServer::HandleCopyScene(HandlerContext & ctx, const Commands::CopySce
10251058
response.groupIdentifierFrom = req.groupIdentifierFrom;
10261059
response.sceneIdentifierFrom = req.sceneIdentifierFrom;
10271060

1061+
// Verify the attributes are respecting constraints
1062+
if (req.sceneIdentifierFrom == scenes::kUndefinedSceneId || req.sceneIdentifierTo == scenes::kUndefinedSceneId)
1063+
{
1064+
response.status = to_underlying(Protocols::InteractionModel::Status::ResourceExhausted);
1065+
ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response);
1066+
return;
1067+
}
1068+
10281069
// Verify Endpoint in group
10291070
VerifyOrReturn(nullptr != mGroupProvider);
10301071
if ((0 != req.groupIdentifierFrom &&

src/app/tests/suites/certification/Test_TC_S_2_2.yaml

+112-5
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,27 @@ tests:
302302
- name: "SceneID"
303303
value: 0x01
304304

305+
- label:
306+
"Step 2d: TH sends a StoreScene command to DUT with the GroupID field
307+
set to G1 and the SceneID field set to 0xFF, which is outside of the
308+
constraints for a SceneID."
309+
PICS: S.S.C04.Rsp
310+
command: "StoreScene"
311+
arguments:
312+
values:
313+
- name: "GroupID"
314+
value: GI
315+
- name: "SceneID"
316+
value: 0xFF
317+
response:
318+
values:
319+
- name: "Status"
320+
value: 0x87
321+
- name: "GroupID"
322+
value: GI
323+
- name: "SceneID"
324+
value: 0xFF
325+
305326
- label:
306327
"Step 3a: TH configures AC2 on DUT for all implemented application
307328
clusters supporting scenes."
@@ -444,6 +465,21 @@ tests:
444465
- name: "SceneID"
445466
value: 0x01
446467

468+
- label:
469+
"Step 4e: TH sends a RecallScene command to DUT with the GroupID field
470+
set to G1 and the SceneID field set to 0xFF, which is outside of the
471+
constraints for a SceneID."
472+
PICS: S.S.C05.Rsp
473+
command: "RecallScene"
474+
arguments:
475+
values:
476+
- name: "GroupID"
477+
value: G1
478+
- name: "SceneID"
479+
value: 0xFF
480+
response:
481+
error: CONSTRAINT_ERROR
482+
447483
- label:
448484
"Step 5a: TH sends a ViewScene command to DUT with the GroupID field
449485
set to G1 and the SceneID field set to 0x01."
@@ -555,6 +591,27 @@ tests:
555591
- name: "SceneID"
556592
value: 0xFE
557593

594+
- label:
595+
"Step 5d: TH sends a ViewScene command to DUT with the GroupID field
596+
set to G1 and the SceneID field set to 0xFF, which is outside of the
597+
constraints for a SceneID."
598+
PICS: S.S.C01.Rsp
599+
command: "ViewScene"
600+
arguments:
601+
values:
602+
- name: "GroupID"
603+
value: G1
604+
- name: "SceneID"
605+
value: 0xFF
606+
response:
607+
values:
608+
- name: "Status"
609+
value: 0x87
610+
- name: "GroupID"
611+
value: G1
612+
- name: "SceneID"
613+
value: 0xFF
614+
558615
- label:
559616
"Step 6: TH sends a GetSceneMembership command to DUT with the GroupID
560617
field set to G1."
@@ -734,7 +791,7 @@ tests:
734791
"Step 8d: TH sends a AddScene command to DUT with the GroupID field
735792
set to G1, the SceneID field set to 0x01, the TransitionTime field set
736793
to 70 000 000 (70 000s) and no extension field sets. This should fail
737-
and return a status of 0x85 (INVALID_COMMAND)."
794+
and return a status of 0x87 (CONSTRAINT_ERROR)."
738795
PICS: S.S.C00.Rsp
739796
command: "AddScene"
740797
arguments:
@@ -752,7 +809,7 @@ tests:
752809
response:
753810
values:
754811
- name: "Status"
755-
value: 0x85
812+
value: 0x87
756813
- name: "GroupID"
757814
value: G1
758815
- name: "SceneID"
@@ -762,7 +819,7 @@ tests:
762819
"Step 8e: TH sends a AddScene command to DUT with the GroupID field
763820
set to G1, the SceneID field set to 0x01, the TransitionTime field set
764821
to 60 000 001 (60 000.001s) and no extension field sets. This should
765-
fail and return a status of 0x85 (INVALID_COMMAND)."
822+
fail and return a status of 0x87 (CONSTRAINT_ERROR)."
766823
PICS: S.S.C00.Rsp
767824
command: "AddScene"
768825
arguments:
@@ -780,12 +837,41 @@ tests:
780837
response:
781838
values:
782839
- name: "Status"
783-
value: 0x85
840+
value: 0x87
784841
- name: "GroupID"
785842
value: G1
786843
- name: "SceneID"
787844
value: 0x01
788845

846+
- label:
847+
"Step 8f: TH sends a AddScene command to DUT with the GroupID field
848+
set to G1, the SceneID field set to 0xFF, which is outside of the
849+
constraints for a SceneID, the TransitionTime field set to 1000 (1s)
850+
and no extension field sets. This should fail and return a status of
851+
0x87 (CONSTRAINT_ERROR)."
852+
PICS: S.S.C00.Rsp
853+
command: "AddScene"
854+
arguments:
855+
values:
856+
- name: "GroupID"
857+
value: G1
858+
- name: "SceneID"
859+
value: 0xFF
860+
- name: "TransitionTime"
861+
value: 1000
862+
- name: "SceneName"
863+
value: "Scene1"
864+
- name: "ExtensionFieldSets"
865+
value: []
866+
response:
867+
values:
868+
- name: "Status"
869+
value: 0x87
870+
- name: "GroupID"
871+
value: G1
872+
- name: "SceneID"
873+
value: 0xFF
874+
789875
- label:
790876
"Step 9a: TH sends a RemoveScene command to DUT with the GroupID field
791877
set to G1 and the SceneID field set to 0x01."
@@ -848,7 +934,28 @@ tests:
848934
value: 0x01
849935

850936
- label:
851-
"Step 9d: TH sends a GetSceneMembership command to DUT with the
937+
"Step 9d: TH sends a RemoveScene command to DUT with the GroupID field
938+
set to G1 and the SceneID field set to 0xFF, which is outside of the
939+
constraints for a SceneID."
940+
PICS: S.S.C02.Rsp
941+
command: "RemoveScene"
942+
arguments:
943+
values:
944+
- name: "GroupID"
945+
value: GI
946+
- name: "SceneID"
947+
value: 0xFF
948+
response:
949+
values:
950+
- name: "Status"
951+
value: 0x87
952+
- name: "GroupID"
953+
value: GI
954+
- name: "SceneID"
955+
value: 0xFF
956+
957+
- label:
958+
"Step 9e: TH sends a GetSceneMembership command to DUT with the
852959
GroupID field set to G1."
853960
PICS: S.S.C06.Rsp
854961
command: "GetSceneMembership"

0 commit comments

Comments
 (0)