Create a copy of bytes for each channel decrypt

This commit is contained in:
Eric Severance 2024-12-19 12:49:17 -08:00
parent 42c8eaf22b
commit a597384040
No known key found for this signature in database
GPG Key ID: 340D1DA2A5A64A62

View File

@ -357,12 +357,13 @@ bool perhapsDecode(meshtastic_MeshPacket *p)
// assert(p->which_payloadVariant == MeshPacket_encrypted_tag); // assert(p->which_payloadVariant == MeshPacket_encrypted_tag);
if (!decrypted) { if (!decrypted) {
memcpy(bytes, p->encrypted.bytes,
rawSize); // we have to copy into a scratch buffer, because these bytes are a union with the decoded protobuf
// Try to find a channel that works with this hash // Try to find a channel that works with this hash
for (chIndex = 0; chIndex < channels.getNumChannels(); chIndex++) { for (chIndex = 0; chIndex < channels.getNumChannels(); chIndex++) {
// Try to use this hash/channel pair // Try to use this hash/channel pair
if (channels.decryptForHash(chIndex, p->channel)) { if (channels.decryptForHash(chIndex, p->channel)) {
// we have to copy into a scratch buffer, because these bytes are a union with the decoded protobuf. Create a
// fresh copy for each decrypt attempt.
memcpy(bytes, p->encrypted.bytes, rawSize);
// Try to decrypt the packet if we can // Try to decrypt the packet if we can
crypto->decrypt(p->from, p->id, rawSize, bytes); crypto->decrypt(p->from, p->id, rawSize, bytes);