From c7b48b0ff5d76655d0c071d30730facb8e360821 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 6 Feb 2023 13:16:38 -0500 Subject: [PATCH] Simplfy and future-proof enum range checks in door locks. Instead of explicitly checking for the min/max values, check for the "unknown value" value that decoding will decode to if the value is out of range. Fixes https://github.com/project-chip/connectedhomeip/issues/20936 --- .../clusters/door-lock-server/door-lock-server.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 6fb25e34e3d02c..d930351e1108a3 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -380,11 +380,10 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb return; } - if (!userType.IsNull() && - (userType.Value() < UserTypeEnum::kUnrestrictedUser || userType.Value() > UserTypeEnum::kRemoteOnlyUser)) + if (!userType.IsNull() && userType.Value() == UserTypeEnum::kUnknownEnumValue) { emberAfDoorLockClusterPrintln( - "[SetUser] Unable to set the user: user type is out of range [endpointId=%d,userIndex=%d,userType=%u]", + "[SetUser] Unable to set the user: user type is unknown [endpointId=%d,userIndex=%d,userType=%u]", commandPath.mEndpointId, userIndex, to_underlying(userType.Value())); sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_INVALID_COMMAND); @@ -694,10 +693,9 @@ void DoorLockServer::setCredentialCommandHandler( return; } - if (!userType.IsNull() && - (userType.Value() < UserTypeEnum::kUnrestrictedUser || userType.Value() > UserTypeEnum::kRemoteOnlyUser)) + if (!userType.IsNull() && userType.Value() == UserTypeEnum::kUnknownEnumValue) { - emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: user type is out of range " + emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: user type is unknown " "[endpointId=%d,credentialIndex=%d,userType=%u]", commandPath.mEndpointId, credentialIndex, to_underlying(userType.Value())); sendSetCredentialResponse(commandObj, commandPath, DlStatus::kInvalidField, 0, nextAvailableCredentialSlot); @@ -3113,9 +3111,9 @@ void DoorLockServer::setHolidayScheduleCommandHandler(chip::app::CommandHandler return; } - if (operatingMode > OperatingModeEnum::kPassage || operatingMode < OperatingModeEnum::kNormal) + if (operatingMode == OperatingModeEnum::kUnknownEnumValue) { - emberAfDoorLockClusterPrintln("[SetHolidaySchedule] Unable to add schedule - operating mode is out of range" + emberAfDoorLockClusterPrintln("[SetHolidaySchedule] Unable to add schedule - operating mode is unknown" "[endpointId=%d,scheduleIndex=%d,localStarTime=%" PRIu32 ",localEndTime=%" PRIu32 ", operatingMode=%d]", endpointId, holidayIndex, localStartTime, localEndTime, to_underlying(operatingMode));