Skip to content

Commit b67decf

Browse files
author
Scott Powell
committed
* bug fix: Packet::writeTo(), Packet::readFrom()
1 parent ca81f64 commit b67decf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Packet.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
5757
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
5858
}
5959
dest[i++] = path_len;
60-
memcpy(&dest[i], path, path_len); i += path_len;
60+
i += writePath(&dest[i], path, path_len);
6161
memcpy(&dest[i], payload, payload_len); i += payload_len;
6262
return i;
6363
}
@@ -72,8 +72,11 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
7272
transport_codes[0] = transport_codes[1] = 0;
7373
}
7474
path_len = src[i++];
75-
if (path_len > sizeof(path)) return false; // bad encoding
76-
memcpy(path, &src[i], path_len); i += path_len;
75+
if (!isValidPathLen(path_len)) return false; // bad encoding
76+
77+
uint8_t bl = getPathByteLen();
78+
memcpy(path, &src[i], bl); i += bl;
79+
7780
if (i >= len) return false; // bad encoding
7881
payload_len = len - i;
7982
if (payload_len > sizeof(payload)) return false; // bad encoding

0 commit comments

Comments
 (0)