Skip to content

Commit b63d24c

Browse files
committed
fix(zwapi): Prevent injection while refreshing caps
This fix isolated to test the following test (with and without/revert) it. The issue should be detected sooner (before calling zwapi_session_flush_queue) 2025-Jun-20 16:34:15.434395 <E> [zwapi_init] zwapi_refresh_capabilities: invalid supported_bitmask Origin: SiliconLabsSoftware#125 Bug-SiliconLabs: UIC-3664 Relate-to: SLVDBBP-3162484 Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#42 Signed-off-by: Philippe Coval <[email protected]>
1 parent 31cb0ba commit b63d24c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

applications/zpc/components/zwave_api/src/zwapi_init.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ sl_status_t zwapi_refresh_capabilities(void)
161161
"Failed to fetch capabilities from the Z-Wave module\n");
162162
return capabilities_status;
163163
}
164-
if (response_length > (IDX_DATA + 7)) {
164+
if (response_length > (IDX_DATA + 7) && (response_length <= FRAME_LENGTH_MAX)) {
165165
uint8_t current_index = IDX_DATA;
166166
chip.version_major = response_buffer[current_index++];
167167
chip.version_minor = response_buffer[current_index++];
@@ -171,9 +171,14 @@ sl_status_t zwapi_refresh_capabilities(void)
171171
chip.product_type |= response_buffer[current_index++];
172172
chip.product_id = response_buffer[current_index++] << 8;
173173
chip.product_id |= response_buffer[current_index++];
174+
size_t length = response_length - (current_index - 1);
175+
if (length > sizeof(chip.supported_bitmask)) {
176+
sl_log_error(LOG_TAG, "zwapi_refresh_capabilities: invalid supported_bitmask\n");
177+
return SL_STATUS_FAIL;
178+
}
174179
memcpy(chip.supported_bitmask,
175-
&(response_buffer[current_index]),
176-
response_length - (current_index - 1));
180+
&(response_buffer[current_index]),
181+
length);
177182
} else {
178183
return SL_STATUS_FAIL;
179184
}

0 commit comments

Comments
 (0)