Skip to content

Commit 3a7bec0

Browse files
committed
fix(zwapi) Harden zwapi_connection_tx in zwapi_connection.c
Change is obvious, it prevent an overflow, Also it has been observed than on edge case (0xFF) the counter never ends because it loops on the range of i that was defined as a char, let's use a larger range. 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), Also lenght is strored on 8bits which align to the frame max (0xFF/ 255). Origin: SiliconLabsSoftware#127 Bug-SiliconLabs: UIC-3666 Bug-SLVDBBP: 3169925 Signed-off-by: Philippe Coval <[email protected]>
1 parent 2e96957 commit 3a7bec0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@ 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
143+
= sizeof(tx_buffer) - 4 - 1; // 255 - 5 = 250
144+
if (len > MAX_PAYLOAD_LEN_ALLOWED) {
145+
sl_log_error(LOG_TAG,
146+
"zwapi_connection_tx: Buffer overflow prevented: Payload length (%u) exceeds "
147+
"maximum allowed (%zu).\n",
148+
len,
149+
MAX_PAYLOAD_LEN_ALLOWED);
150+
assert(false);
151+
return;
152+
}
153+
142154
uint8_t *c;
143155
c = tx_buffer;
144156

@@ -151,7 +163,7 @@ void zwapi_connection_tx(
151163
c += len;
152164

153165
uint8_t tx_checksum = 0xFF;
154-
for (uint8_t i = 0; i < len + 3; i++) {
166+
for (uint16_t i = 0; i < len + 3; i++) {
155167
tx_checksum ^= tx_buffer[i + 1];
156168
}
157169
*c++ = tx_checksum;

0 commit comments

Comments
 (0)