Skip to content

Commit bc32968

Browse files
committed
Merge pull request arduino#317 from tekka007/nullTerminationFix
Fix null termination issue
2 parents f895bba + cfed7a2 commit bc32968

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libraries/MySensors/core/MyTransport.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ inline void transportProcess() {
7474
(void)signerCheckTimer(); // Manage signing timeout
7575
#endif
7676

77-
uint8_t len = transportReceive((uint8_t *)&_msg);
78-
(void)len; //until somebody makes use of 'len'
77+
uint8_t payloadLength = transportReceive((uint8_t *)&_msg);
78+
(void)payloadLength; //until somebody makes use of it
7979
ledBlinkRx(1);
8080

81+
8182
uint8_t command = mGetCommand(_msg);
8283
uint8_t type = _msg.type;
8384
uint8_t sender = _msg.sender;
8485
uint8_t last = _msg.last;
8586
uint8_t destination = _msg.destination;
87+
8688

8789
#ifdef MY_SIGNING_FEATURE
8890
// Before processing message, reject unsigned messages if signing is required and check signature (if it is signed and addressed to us)
@@ -137,7 +139,11 @@ inline void transportProcess() {
137139
if (destination == _nc.nodeId) {
138140
// This message is addressed to this node
139141
mSetSigned(_msg,0); // Clear the sign-flag now as verification is completed
140-
142+
// prevent buffer overflow by limiting max. possible message length (5 bits=31 bytes max) to MAX_PAYLOAD (25 bytes)
143+
mSetLength(_msg, min(mGetLength(_msg),MAX_PAYLOAD));
144+
// null terminate data
145+
_msg.data[mGetLength(_msg)] = 0x00;
146+
141147
#if defined(MY_REPEATER_FEATURE)
142148
if (_msg.last != _nc.parentNodeId) {
143149
// Message is from one of the child nodes. Add it to routing table.

0 commit comments

Comments
 (0)