Licensed channel defaults, phone map growth, and payload read bounds (#11286)
* Strip the default PSK when licensed defaults are installed * Only record rate-limited portnums from the phone * Bound payload reads by the received size
This commit is contained in:
co-authored by
GitHub
parent
df6e67f70b
commit
daf1213580
@@ -215,7 +215,12 @@ const StoredMessage *MessageStore::tryAddFromPacket(const meshtastic_MeshPacket
|
||||
sm.channelIndex = packet.channel;
|
||||
|
||||
const char *payload = reinterpret_cast<const char *>(packet.decoded.payload.bytes);
|
||||
size_t len = strnlen(payload, MAX_MESSAGE_SIZE - 1);
|
||||
// payload.bytes is not NUL-terminated, so bound by the received size too: a shorter message
|
||||
// stored after a longer one would otherwise pick up the previous occupant's trailing bytes.
|
||||
size_t avail = packet.decoded.payload.size;
|
||||
if (avail > MAX_MESSAGE_SIZE - 1)
|
||||
avail = MAX_MESSAGE_SIZE - 1;
|
||||
size_t len = strnlen(payload, avail);
|
||||
sm.textOffset = storeTextInPool(payload, len);
|
||||
sm.textLength = len;
|
||||
|
||||
|
||||
@@ -741,6 +741,10 @@ void NodeDB::resetRadioConfig(bool is_fresh_install)
|
||||
LOG_INFO("Set default channel and radio preferences!");
|
||||
|
||||
channels.initDefaults();
|
||||
// Defaults ship the public PSK, so strip it again before onConfigChanged() publishes hashes;
|
||||
// loadFromDisk's sanitation is a no-op when the channel file was absent or corrupt.
|
||||
if (owner.is_licensed)
|
||||
channels.ensureLicensedOperation();
|
||||
}
|
||||
|
||||
channels.onConfigChanged();
|
||||
|
||||
@@ -1855,7 +1855,12 @@ bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p)
|
||||
p.want_ack = true;
|
||||
}
|
||||
|
||||
lastPortNumToRadio[p.decoded.portnum] = millis();
|
||||
// Only the rate-limited ports above are ever read back, so recording any other portnum would let
|
||||
// a client grow this map without bound by cycling through them.
|
||||
if (IS_ONE_OF(p.decoded.portnum, meshtastic_PortNum_TRACEROUTE_APP, meshtastic_PortNum_POSITION_APP,
|
||||
meshtastic_PortNum_WAYPOINT_APP, meshtastic_PortNum_ALERT_APP, meshtastic_PortNum_TELEMETRY_APP,
|
||||
meshtastic_PortNum_TEXT_MESSAGE_APP))
|
||||
lastPortNumToRadio[p.decoded.portnum] = millis();
|
||||
service->handleToRadio(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,14 +32,17 @@ ProcessMessage DropzoneModule::handleReceived(const meshtastic_MeshPacket &mp)
|
||||
auto &p = mp.decoded;
|
||||
char matchCompare[54];
|
||||
auto incomingMessage = reinterpret_cast<const char *>(p.payload.bytes);
|
||||
sprintf(matchCompare, "%s conditions", owner.short_name);
|
||||
if (strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
|
||||
// payload.bytes is not NUL-terminated, so a comparison longer than the received size would read
|
||||
// whatever the previous occupant of the packet left behind.
|
||||
const size_t received = p.payload.size;
|
||||
snprintf(matchCompare, sizeof(matchCompare), "%s conditions", owner.short_name);
|
||||
if (received >= strlen(matchCompare) && strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
|
||||
LOG_DEBUG("Received dropzone conditions request");
|
||||
startSendConditions = millis();
|
||||
}
|
||||
|
||||
sprintf(matchCompare, "%s conditions", owner.long_name);
|
||||
if (strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
|
||||
snprintf(matchCompare, sizeof(matchCompare), "%s conditions", owner.long_name);
|
||||
if (received >= strlen(matchCompare) && strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
|
||||
LOG_DEBUG("Received dropzone conditions request");
|
||||
startSendConditions = millis();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user