Skip to content

Commit b14879c

Browse files
author
Scott Powell
committed
* CMD_GET_ADVERT_PATH bug fix
1 parent 9d5c486 commit b14879c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

examples/companion_radio/MyMesh.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
350350
}
351351

352352
// add inbound-path to mem cache
353-
if (path && path_len <= sizeof(AdvertPath::path)) { // check path is valid
353+
if (path && mesh::Packet::isValidPathLen(path_len)) { // check path is valid
354354
AdvertPath* p = advert_paths;
355355
uint32_t oldest = 0xFFFFFFFF;
356356
for (int i = 0; i < ADVERT_PATH_TABLE_SIZE; i++) { // check if already in table, otherwise evict oldest
@@ -367,8 +367,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
367367
memcpy(p->pubkey_prefix, contact.id.pub_key, sizeof(p->pubkey_prefix));
368368
strcpy(p->name, contact.name);
369369
p->recv_timestamp = getRTCClock()->getCurrentTime();
370-
p->path_len = path_len;
371-
memcpy(p->path, path, p->path_len);
370+
p->path_len = mesh::Packet::copyPath(p->path, path, path_len);
372371
}
373372

374373
if (!is_new) dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // only schedule lazy write for contacts that are in contacts[]
@@ -1696,11 +1695,12 @@ void MyMesh::handleCmdFrame(size_t len) {
16961695
}
16971696
}
16981697
if (found) {
1699-
out_frame[0] = RESP_CODE_ADVERT_PATH;
1700-
memcpy(&out_frame[1], &found->recv_timestamp, 4);
1701-
out_frame[5] = found->path_len;
1702-
memcpy(&out_frame[6], found->path, found->path_len);
1703-
_serial->writeFrame(out_frame, 6 + found->path_len);
1698+
int i = 0;
1699+
out_frame[i++] = RESP_CODE_ADVERT_PATH;
1700+
memcpy(&out_frame[i], &found->recv_timestamp, 4); i += 4;
1701+
out_frame[i++] = found->path_len;
1702+
i += mesh::Packet::writePath(&out_frame[i], found->path, found->path_len);
1703+
_serial->writeFrame(out_frame, i);
17041704
} else {
17051705
writeErrFrame(ERR_CODE_NOT_FOUND);
17061706
}

0 commit comments

Comments
 (0)