Skip to content

Commit 3dd6cda

Browse files
committed
fix(zwapi) Harden zwapi_connection_tx in zwapi_connection.c
Change is obvious, it prevent an overflow, note that functions did not test all inputs params specially when it is done in caller (eg: in zwave_api_send_data reject frames above limit). Bug-SiliconLabs: UIC-3666 Bug-SLVDBBP: 3169925 Signed-off-by: Philippe Coval <[email protected]>
1 parent 85e13a7 commit 3dd6cda

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,21 @@ void zwapi_connection_tx(
138138
uint8_t len, /* IN the length of DATA to transmit */
139139
bool ack_needed)
140140
{
141-
uint8_t tx_buffer[255];
141+
uint8_t tx_buffer[FRAME_LENGTH_MAX];
142+
const size_t MAX_PAYLOAD_LEN_ALLOWED = sizeof(tx_buffer) - 4 - 1; // 255 - 5 = 250
142143
uint8_t *c;
143144
c = tx_buffer;
144145

145146
*c++ = SOF;
146147
*c++ = len + 3;
147148
*c++ = type;
148149
*c++ = cmd;
149-
150+
if (len > MAX_PAYLOAD_LEN_ALLOWED) {
151+
sl_log_error(LOG_TAG, "Buffer overflow prevented: Payload length (%u) exceeds maximum allowed (%zu).\n", len,
152+
MAX_PAYLOAD_LEN_ALLOWED);
153+
assert(false);
154+
return;
155+
}
150156
memcpy(c, Buf, len);
151157
c += len;
152158

0 commit comments

Comments
 (0)