Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow associating a node with itself and skip self-associations when rebuilding routes #6749

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/cc/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export function isAssociationAllowed(
// The following checks don't apply to Lifeline associations
if (destination.nodeId === applHost.ownNodeId) return true;

// Disallow self-associations
if (destination.nodeId === endpoint.nodeId) return false;

// For Association version 1 and version 2 / MCA version 1-3:
// A controlling node MUST NOT associate Node A to a Node B destination
// if Node A and Node B’s highest Security Class are not identical.
Expand Down Expand Up @@ -362,6 +365,15 @@ export async function addAssociations(
);
}

// Disallow associating a node with itself. This is technically checked as part of
// isAssociationAllowed, but here we provide a better error message.
if (destinations.some((d) => d.nodeId === endpoint.nodeId)) {
throw new ZWaveError(
`Associating a node with itself is not allowed!`,
ZWaveErrorCodes.AssociationCC_NotAllowed,
);
}

const assocGroupCount =
assocInstance?.getGroupCountCached(applHost, endpoint) ?? 0;
const mcGroupCount = mcInstance?.getGroupCountCached(applHost, endpoint)
Expand Down
2 changes: 2 additions & 0 deletions packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,8 @@ supported CCs: ${
)
// ...except the controller itself, which was handled by step 2
.filter((id) => id !== this._ownNodeId!)
// ...and the node itself
.filter((id) => id !== nodeId)
.sort();
} catch {
/* ignore */
Expand Down
Loading