Skip to content

Commit ff48ee4

Browse files
committed
do not trust received msg length to read forever
1 parent f7eb248 commit ff48ee4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libraries/Bridge/src/Bridge.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
191191

192192
// Recv data
193193
for (uint16_t i = 0; i < l; i++) {
194+
// Cut received data if rxbuffer is too small
195+
if (i >= rxlen)
196+
break;
194197
int c = timedRead(5);
195198
if (c < 0)
196199
continue;
197-
// Cut received data if rxbuffer is too small
198-
if (i < rxlen)
199-
rxbuff[i] = c;
200+
rxbuff[i] = c;
200201
crcUpdate(c);
201202
}
202203

0 commit comments

Comments
 (0)