fix(contacts): zero ContactInfo before a partial fill
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cb74cdee06
commit
e06d95ed22
3 files changed
+17
No files matched your search
@@ -265,6 +265,12 @@ File file = openRead(_getContactsChannelsFS(), "/contacts3");
|
|||||||
uint8_t pub_key[32];
|
uint8_t pub_key[32];
|
||||||
uint8_t unused;
|
uint8_t unused;
|
||||||
|
|
||||||
|
// The on-disk record has no shared_secret/shared_secret_valid, so those
|
||||||
|
// two members are never written by the reads below. Left indeterminate,
|
||||||
|
// a non-zero shared_secret_valid makes getSharedSecret() return an
|
||||||
|
// uninitialised secret for a contact loaded at boot.
|
||||||
|
memset(&c, 0, sizeof(c));
|
||||||
|
|
||||||
bool success = (file.read(pub_key, 32) == 32);
|
bool success = (file.read(pub_key, 32) == 32);
|
||||||
success = success && (file.read((uint8_t *)&c.name, 32) == 32);
|
success = success && (file.read((uint8_t *)&c.name, 32) == 32);
|
||||||
success = success && (file.read(&c.type, 1) == 1);
|
success = success && (file.read(&c.type, 1) == 1);
|
||||||
|
|||||||
@@ -1307,6 +1307,13 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
} else {
|
} else {
|
||||||
ContactInfo contact;
|
ContactInfo contact;
|
||||||
|
// The frame's lat/lon/lastmod are optional, and clients omit them when the
|
||||||
|
// contact has no location -- so anything updateContactFromFrame() does not
|
||||||
|
// write stays as whatever was on the stack. That leaks garbage into
|
||||||
|
// gps_lat/gps_lon and, worse, into shared_secret_valid: a non-zero byte
|
||||||
|
// there makes getSharedSecret() hand out an uninitialised secret.
|
||||||
|
// populateContactFromAdvert() zeroes for the same reason.
|
||||||
|
memset(&contact, 0, sizeof(contact));
|
||||||
updateContactFromFrame(contact, last_mod, cmd_frame, len);
|
updateContactFromFrame(contact, last_mod, cmd_frame, len);
|
||||||
contact.lastmod = last_mod;
|
contact.lastmod = last_mod;
|
||||||
contact.sync_since = 0;
|
contact.sync_since = 0;
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
|
|||||||
uint8_t unused;
|
uint8_t unused;
|
||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
|
|
||||||
|
// No shared_secret/shared_secret_valid in the on-disk record; without
|
||||||
|
// this the flag is indeterminate for every contact loaded at boot.
|
||||||
|
memset(&c, 0, sizeof(c));
|
||||||
|
|
||||||
bool success = (file.read(pub_key, 32) == 32);
|
bool success = (file.read(pub_key, 32) == 32);
|
||||||
success = success && (file.read((uint8_t *) &c.name, 32) == 32);
|
success = success && (file.read((uint8_t *) &c.name, 32) == 32);
|
||||||
success = success && (file.read(&c.type, 1) == 1);
|
success = success && (file.read(&c.type, 1) == 1);
|
||||||
|
|||||||
Reference in new issue
Block a user