Skip to content

Commit 23e69c3

Browse files
Make sure we don't trash our userinfo after we get it and before we send it. (project-chip#26373) (project-chip#26421)
findOccupiedUserSlot can end up overwriting some of the buffers that emberAfPluginDoorLockGetUser uses, so we need to make sure we call findOccupiedUserSlot before emberAfPluginDoorLockGetUser (or after we are done using the output from emberAfPluginDoorLockGetUser).
1 parent 4ff8bc7 commit 23e69c3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/app/clusters/door-lock-server/door-lock-server.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,20 @@ void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandOb
453453
return;
454454
}
455455

456+
Commands::GetUserResponse::Type response;
457+
458+
// appclusters, 5.2.4.36.1: We need to add next occupied user after userIndex if any.
459+
//
460+
// We want to do this before we call emberAfPluginDoorLockGetUser, because this will
461+
// make its own emberAfPluginDoorLockGetUser calls, and a
462+
// EmberAfPluginDoorLockUserInfo might be pointing into some application-static
463+
// buffers (for its credentials and whatnot).
464+
uint16_t nextAvailableUserIndex = 0;
465+
if (findOccupiedUserSlot(commandPath.mEndpointId, static_cast<uint16_t>(userIndex + 1), nextAvailableUserIndex))
466+
{
467+
response.nextUserIndex.SetNonNull(nextAvailableUserIndex);
468+
}
469+
456470
EmberAfPluginDoorLockUserInfo user;
457471
if (!emberAfPluginDoorLockGetUser(commandPath.mEndpointId, userIndex, user))
458472
{
@@ -461,7 +475,6 @@ void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandOb
461475
return;
462476
}
463477

464-
Commands::GetUserResponse::Type response;
465478
response.userIndex = userIndex;
466479

467480
// appclusters, 5.2.4.36: we should not set user-specific fields to non-null if the user status is set to Available
@@ -498,12 +511,6 @@ void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandOb
498511
emberAfDoorLockClusterPrintln("[GetUser] User not found [userIndex=%d]", userIndex);
499512
}
500513

501-
// appclusters, 5.2.4.36.1: We need to add next occupied user after userIndex if any.
502-
uint16_t nextAvailableUserIndex = 0;
503-
if (findOccupiedUserSlot(commandPath.mEndpointId, static_cast<uint16_t>(userIndex + 1), nextAvailableUserIndex))
504-
{
505-
response.nextUserIndex.SetNonNull(nextAvailableUserIndex);
506-
}
507514
commandObj->AddResponse(commandPath, response);
508515
}
509516

0 commit comments

Comments
 (0)