Skip to content

Commit 7a0ff98

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 By the way, It has been observed that using z-wave-stack-binaries length is clamped from 33 to 31 (this is unexpected, it could be caused by non aligned defs). Origin: SiliconLabsSoftware#126 Relate-to: 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 2ac8717 commit 7a0ff98

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ 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)
165+
&& (response_length <= FRAME_LENGTH_MAX)) {
165166
uint8_t current_index = IDX_DATA;
166167
chip.version_major = response_buffer[current_index++];
167168
chip.version_minor = response_buffer[current_index++];
@@ -171,9 +172,16 @@ sl_status_t zwapi_refresh_capabilities(void)
171172
chip.product_type |= response_buffer[current_index++];
172173
chip.product_id = response_buffer[current_index++] << 8;
173174
chip.product_id |= response_buffer[current_index++];
174-
memcpy(chip.supported_bitmask,
175-
&(response_buffer[current_index]),
176-
response_length - (current_index - 1));
175+
size_t length = response_length - (current_index - 1);
176+
if (length > sizeof(chip.supported_bitmask)) {
177+
sl_log_warning(
178+
LOG_TAG,
179+
"zwapi_refresh_capabilities: clamping supported_bitmask response from %d to %d\n",
180+
length,
181+
sizeof(chip.supported_bitmask));
182+
length = sizeof(chip.supported_bitmask);
183+
}
184+
memcpy(chip.supported_bitmask, &(response_buffer[current_index]), length);
177185
} else {
178186
return SL_STATUS_FAIL;
179187
}

0 commit comments

Comments
 (0)