Terminate contact names received from the app
updateContactFromFrame() copies 32 name bytes from the companion frame without terminating them, so an app (or a corrupt frame) can store a name with no NUL. The UI then passes it to sprintf() into fixed-size origin buffers. Terminate the name on receipt and use snprintf() in both UIs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
505ae195dd
commit
e86ed1373b
3 files changed
+7
-6
No files matched your search
@@ -202,6 +202,7 @@ void MyMesh::updateContactFromFrame(ContactInfo &contact, uint32_t& last_mod, co
|
|||||||
memcpy(contact.out_path, &frame[i], MAX_PATH_SIZE);
|
memcpy(contact.out_path, &frame[i], MAX_PATH_SIZE);
|
||||||
i += MAX_PATH_SIZE;
|
i += MAX_PATH_SIZE;
|
||||||
memcpy(contact.name, &frame[i], 32);
|
memcpy(contact.name, &frame[i], 32);
|
||||||
|
contact.name[sizeof(contact.name) - 1] = 0; // the app is not trusted to NUL-terminate
|
||||||
i += 32;
|
i += 32;
|
||||||
memcpy(&contact.last_advert_timestamp, &frame[i], 4);
|
memcpy(&contact.last_advert_timestamp, &frame[i], 4);
|
||||||
i += 4;
|
i += 4;
|
||||||
|
|||||||
@@ -739,9 +739,9 @@ public:
|
|||||||
auto p = &unread[head];
|
auto p = &unread[head];
|
||||||
p->timestamp = _rtc->getCurrentTime();
|
p->timestamp = _rtc->getCurrentTime();
|
||||||
if (path_count == 0xFF) {
|
if (path_count == 0xFF) {
|
||||||
sprintf(p->origin, "(D) %s:", from_name);
|
snprintf(p->origin, sizeof(p->origin), "(D) %s:", from_name);
|
||||||
} else {
|
} else {
|
||||||
sprintf(p->origin, "(%d) %s:", (uint32_t) path_count, from_name);
|
snprintf(p->origin, sizeof(p->origin), "(%d) %s:", (uint32_t) path_count, from_name);
|
||||||
}
|
}
|
||||||
StrHelper::strncpy(p->msg, msg, sizeof(p->msg));
|
StrHelper::strncpy(p->msg, msg, sizeof(p->msg));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,9 +155,9 @@ void UITask::onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t t
|
|||||||
|
|
||||||
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
||||||
if (path_len == 0xFF) {
|
if (path_len == 0xFF) {
|
||||||
sprintf(_origin, "(F) %s", from.name);
|
snprintf(_origin, sizeof(_origin), "(F) %s", from.name);
|
||||||
} else {
|
} else {
|
||||||
sprintf(_origin, "(%d) %s", (uint32_t) path_len, from.name);
|
snprintf(_origin, sizeof(_origin), "(%d) %s", (uint32_t) path_len, from.name);
|
||||||
}
|
}
|
||||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ void UITask::onChannelMessageRecv(mesh::Packet *pkt, ChannelDetails& channel_det
|
|||||||
|
|
||||||
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
uint8_t path_len = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
|
||||||
if (path_len == 0xFF) {
|
if (path_len == 0xFF) {
|
||||||
sprintf(_origin, "(F) %s", channel_details.name);
|
snprintf(_origin, sizeof(_origin), "(F) %s", channel_details.name);
|
||||||
} else {
|
} else {
|
||||||
sprintf(_origin, "(%d) %s", (uint32_t) path_len, channel_details.name);
|
snprintf(_origin, sizeof(_origin), "(%d) %s", (uint32_t) path_len, channel_details.name);
|
||||||
}
|
}
|
||||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user