fix(companion): null-terminate contact name in CMD_ADD_UPDATE_CONTACT

The wire format reserves a 32-byte name field; if the phone sends 32
non-null bytes, ContactInfo::name has no terminator. Subsequent
LOG_INF/LOG_DBG sites using %s with contact.name then read past the
field into adjacent struct bytes (type, flags, out_path_len, ...)
until the first null. No memory corruption — serializeContact uses
StrHelper::strzcpy which is length-bounded — but log output gets
garbage and a paired peer could probe a few bytes of the struct
through log capture.

Sibling handler CMD_SET_CHANNEL at :1593-1594 already does this
defensively. Match the pattern.
This commit is contained in:
liquidraver
2026-05-20 15:40:18 +02:00
parent 988b438ec3
commit b39483add3
+1
View File
@@ -1484,6 +1484,7 @@ bool CompanionMesh::handleProtocolFrame(const uint8_t *data, size_t len)
c.out_path_len = data[i++];
memcpy(c.out_path, &data[i], MAX_PATH_SIZE); i += MAX_PATH_SIZE;
memcpy(c.name, &data[i], 32); i += 32;
c.name[31] = '\0'; /* defensive null-term — matches CMD_SET_CHANNEL pattern */
c.last_advert_timestamp = get_le32(&data[i]); i += 4;
c.gps_lat = 0;
c.gps_lon = 0;