diff --git a/src/main.cpp b/src/main.cpp index 4083bfac3..63cbf35ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1053,10 +1053,12 @@ void setup() if (nodeDB->keyIsLowEntropy && !nodeDB->hasWarned) { LOG_WARN(LOW_ENTROPY_WARNING); meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_WARNING; - cn->time = getValidTime(RTCQualityFromNet); - sprintf(cn->message, LOW_ENTROPY_WARNING); - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_WARNING; + cn->time = getValidTime(RTCQualityFromNet); + sprintf(cn->message, LOW_ENTROPY_WARNING); + service->sendClientNotification(cn); + } nodeDB->hasWarned = true; } #endif diff --git a/src/modules/KeyVerificationModule.cpp b/src/modules/KeyVerificationModule.cpp index 67317ac9b..de3474aa2 100644 --- a/src/modules/KeyVerificationModule.cpp +++ b/src/modules/KeyVerificationModule.cpp @@ -81,14 +81,16 @@ bool KeyVerificationModule::handleReceivedProtobuf(const meshtastic_MeshPacket & });) meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_WARNING; - sprintf(cn->message, "Enter Security Number for Key Verification"); - cn->which_payload_variant = meshtastic_ClientNotification_key_verification_number_request_tag; - cn->payload_variant.key_verification_number_request.nonce = currentNonce; - copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_number_request.remote_longname, - sizeof(cn->payload_variant.key_verification_number_request.remote_longname), - nodeDB->getMeshNode(currentRemoteNode)); - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_WARNING; + snprintf(cn->message, sizeof(cn->message), "Enter Security Number for Key Verification"); + cn->which_payload_variant = meshtastic_ClientNotification_key_verification_number_request_tag; + cn->payload_variant.key_verification_number_request.nonce = currentNonce; + copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_number_request.remote_longname, + sizeof(cn->payload_variant.key_verification_number_request.remote_longname), + nodeDB->getMeshNode(currentRemoteNode)); + service->sendClientNotification(cn); + } LOG_INFO("Received hash2"); currentState = KEY_VERIFICATION_SENDER_AWAITING_NUMBER; return true; @@ -114,15 +116,17 @@ bool KeyVerificationModule::handleReceivedProtobuf(const meshtastic_MeshPacket & }; screen->showOverlayBanner(options);) meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_WARNING; - sprintf(cn->message, "Final confirmation for incoming manual key verification %s", message); - cn->which_payload_variant = meshtastic_ClientNotification_key_verification_final_tag; - cn->payload_variant.key_verification_final.nonce = currentNonce; - copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_final.remote_longname, - sizeof(cn->payload_variant.key_verification_final.remote_longname), - nodeDB->getMeshNode(currentRemoteNode)); - cn->payload_variant.key_verification_final.isSender = false; - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_WARNING; + snprintf(cn->message, sizeof(cn->message), "Final confirmation for incoming manual key verification %s", message); + cn->which_payload_variant = meshtastic_ClientNotification_key_verification_final_tag; + cn->payload_variant.key_verification_final.nonce = currentNonce; + copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_final.remote_longname, + sizeof(cn->payload_variant.key_verification_final.remote_longname), + nodeDB->getMeshNode(currentRemoteNode)); + cn->payload_variant.key_verification_final.isSender = false; + service->sendClientNotification(cn); + } currentState = KEY_VERIFICATION_RECEIVER_AWAITING_USER; return true; @@ -211,16 +215,18 @@ meshtastic_MeshPacket *KeyVerificationModule::allocReply() IF_SCREEN(snprintf(message, 25, "Security Number \n%03u %03u", currentSecurityNumber / 1000, currentSecurityNumber % 1000); screen->showSimpleBanner(message, 30000); LOG_WARN("%s", message);) meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_WARNING; - sprintf(cn->message, "Incoming Key Verification.\nSecurity Number\n%03u %03u", currentSecurityNumber / 1000, - currentSecurityNumber % 1000); - cn->which_payload_variant = meshtastic_ClientNotification_key_verification_number_inform_tag; - cn->payload_variant.key_verification_number_inform.nonce = currentNonce; - copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_number_inform.remote_longname, - sizeof(cn->payload_variant.key_verification_number_inform.remote_longname), - nodeDB->getMeshNode(currentRemoteNode)); - cn->payload_variant.key_verification_number_inform.security_number = currentSecurityNumber; - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_WARNING; + snprintf(cn->message, sizeof(cn->message), "Incoming Key Verification.\nSecurity Number\n%03u %03u", + currentSecurityNumber / 1000, currentSecurityNumber % 1000); + cn->which_payload_variant = meshtastic_ClientNotification_key_verification_number_inform_tag; + cn->payload_variant.key_verification_number_inform.nonce = currentNonce; + copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_number_inform.remote_longname, + sizeof(cn->payload_variant.key_verification_number_inform.remote_longname), + nodeDB->getMeshNode(currentRemoteNode)); + cn->payload_variant.key_verification_number_inform.security_number = currentSecurityNumber; + service->sendClientNotification(cn); + } LOG_WARN("Security Number %04u, nonce %llu", currentSecurityNumber, currentNonce); return responsePacket; } @@ -275,15 +281,17 @@ void KeyVerificationModule::processSecurityNumber(uint32_t incomingNumber) currentState = KEY_VERIFICATION_SENDER_AWAITING_USER; IF_SCREEN(screen->requestMenu(graphics::menuHandler::KeyVerificationFinalPrompt);) meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_WARNING; - sprintf(cn->message, "Final confirmation for outgoing manual key verification %s", message); - cn->which_payload_variant = meshtastic_ClientNotification_key_verification_final_tag; - cn->payload_variant.key_verification_final.nonce = currentNonce; - copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_final.remote_longname, - sizeof(cn->payload_variant.key_verification_final.remote_longname), - nodeDB->getMeshNode(currentRemoteNode)); - cn->payload_variant.key_verification_final.isSender = true; - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_WARNING; + snprintf(cn->message, sizeof(cn->message), "Final confirmation for outgoing manual key verification %s", message); + cn->which_payload_variant = meshtastic_ClientNotification_key_verification_final_tag; + cn->payload_variant.key_verification_final.nonce = currentNonce; + copyNodeLongNameOrUnknown(cn->payload_variant.key_verification_final.remote_longname, + sizeof(cn->payload_variant.key_verification_final.remote_longname), + nodeDB->getMeshNode(currentRemoteNode)); + cn->payload_variant.key_verification_final.isSender = true; + service->sendClientNotification(cn); + } LOG_INFO(message); return; diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index 7b9f29201..c86c54aff 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -69,12 +69,13 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes // if user has changed while packet was not for us, inform phone if (hasChanged && !wasBroadcast && !isToUs(&mp)) { auto packetCopy = packetPool.allocCopy(mp); // Keep a copy of the packet for later analysis + if (packetCopy) { + // Re-encode the user protobuf, as we have stripped out the user.id + packetCopy->decoded.payload.size = pb_encode_to_bytes( + packetCopy->decoded.payload.bytes, sizeof(packetCopy->decoded.payload.bytes), &meshtastic_User_msg, &p); - // Re-encode the user protobuf, as we have stripped out the user.id - packetCopy->decoded.payload.size = pb_encode_to_bytes( - packetCopy->decoded.payload.bytes, sizeof(packetCopy->decoded.payload.bytes), &meshtastic_User_msg, &p); - - service->sendToPhone(packetCopy); + service->sendToPhone(packetCopy); + } } pruneLastNodeInfoCache(); diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 180494042..d3a702946 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -418,12 +418,14 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) && config.power.is_power_saving) { meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed(); - notification->level = meshtastic_LogRecord_Level_INFO; - notification->time = getValidTime(RTCQualityFromNet); - sprintf(notification->message, "Sending position and sleeping for %us interval in a moment", - Default::getConfiguredOrDefaultMs(config.position.position_broadcast_secs, default_broadcast_interval_secs) / - 1000U); - service->sendClientNotification(notification); + if (notification) { + notification->level = meshtastic_LogRecord_Level_INFO; + notification->time = getValidTime(RTCQualityFromNet); + sprintf(notification->message, "Sending position and sleeping for %us interval in a moment", + Default::getConfiguredOrDefaultMs(config.position.position_broadcast_secs, default_broadcast_interval_secs) / + 1000U); + service->sendClientNotification(notification); + } sleepOnNextExecution = true; LOG_DEBUG("Start next execution in 5s, then sleep"); setIntervalFromNow(FIVE_SECONDS_MS); diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 058a5701c..23e8e9790 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -96,10 +96,12 @@ bool SerialModule::isValidConfig(const meshtastic_ModuleConfig_SerialConfig &con LOG_ERROR(warning); #ifndef PIO_UNIT_TESTING meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_ERROR; - cn->time = getValidTime(RTCQualityFromNet); - snprintf(cn->message, sizeof(cn->message), "%s", warning); - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_ERROR; + cn->time = getValidTime(RTCQualityFromNet); + snprintf(cn->message, sizeof(cn->message), "%s", warning); + service->sendClientNotification(cn); + } #endif return false; } diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index 6eec7c671..ceef4dbb6 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -485,13 +485,15 @@ bool AirQualityTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) if (isPowerSavingSensor()) { meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed(); - notification->level = meshtastic_LogRecord_Level_INFO; - notification->time = getValidTime(RTCQualityFromNet); - sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment", - Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.air_quality_interval, - default_telemetry_broadcast_interval_secs) / - 1000U); - service->sendClientNotification(notification); + if (notification) { + notification->level = meshtastic_LogRecord_Level_INFO; + notification->time = getValidTime(RTCQualityFromNet); + sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment", + Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.air_quality_interval, + default_telemetry_broadcast_interval_secs) / + 1000U); + service->sendClientNotification(notification); + } } } } diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8701dac8d..876d9ca07 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -681,13 +681,15 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) if (isPowerSavingSensor()) { meshtastic_ClientNotification *notification = clientNotificationPool.allocZeroed(); - notification->level = meshtastic_LogRecord_Level_INFO; - notification->time = getValidTime(RTCQualityFromNet); - sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment", - Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval, - default_telemetry_broadcast_interval_secs) / - 1000U); - service->sendClientNotification(notification); + if (notification) { + notification->level = meshtastic_LogRecord_Level_INFO; + notification->time = getValidTime(RTCQualityFromNet); + sprintf(notification->message, "Sending telemetry and sleeping for %us interval in a moment", + Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval, + default_telemetry_broadcast_interval_secs) / + 1000U); + service->sendClientNotification(notification); + } } } } diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 1374ef189..b6f0ce24d 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -392,6 +392,8 @@ bool MQTT::publish(const char *topic, const char *payload, bool retained) { if (moduleConfig.mqtt.proxy_to_client_enabled) { meshtastic_MqttClientProxyMessage *msg = mqttClientProxyMessagePool.allocZeroed(); + if (!msg) + return false; msg->which_payload_variant = meshtastic_MqttClientProxyMessage_text_tag; strncpy(msg->topic, topic, sizeof(msg->topic)); msg->topic[sizeof(msg->topic) - 1] = '\0'; @@ -413,6 +415,8 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo { if (moduleConfig.mqtt.proxy_to_client_enabled) { meshtastic_MqttClientProxyMessage *msg = mqttClientProxyMessagePool.allocZeroed(); + if (!msg) + return false; msg->which_payload_variant = meshtastic_MqttClientProxyMessage_data_tag; strncpy(msg->topic, topic, sizeof(msg->topic)); msg->topic[sizeof(msg->topic) - 1] = '\0'; // Ensure null termination @@ -595,11 +599,13 @@ bool MQTT::isValidConfig(const meshtastic_ModuleConfig_MQTTConfig &config, MQTTC LOG_ERROR(warning); #ifndef PIO_UNIT_TESTING meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_ERROR; - cn->time = getValidTime(RTCQualityFromNet); - strncpy(cn->message, warning, sizeof(cn->message) - 1); - cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_ERROR; + cn->time = getValidTime(RTCQualityFromNet); + strncpy(cn->message, warning, sizeof(cn->message) - 1); + cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination + service->sendClientNotification(cn); + } #endif return false; #endif @@ -611,11 +617,13 @@ bool MQTT::isValidConfig(const meshtastic_ModuleConfig_MQTTConfig &config, MQTTC LOG_ERROR(warning); #ifndef PIO_UNIT_TESTING meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed(); - cn->level = meshtastic_LogRecord_Level_ERROR; - cn->time = getValidTime(RTCQualityFromNet); - strncpy(cn->message, warning, sizeof(cn->message) - 1); - cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination - service->sendClientNotification(cn); + if (cn) { + cn->level = meshtastic_LogRecord_Level_ERROR; + cn->time = getValidTime(RTCQualityFromNet); + strncpy(cn->message, warning, sizeof(cn->message) - 1); + cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination + service->sendClientNotification(cn); + } #endif return false; } @@ -746,6 +754,8 @@ void MQTT::perhapsReportToMap() // Allocate MeshPacket and fill it meshtastic_MeshPacket *mp = packetPool.allocZeroed(); + if (!mp) + return; mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; mp->from = nodeDB->getNodeNum(); mp->to = NODENUM_BROADCAST; diff --git a/src/platform/portduino/SimRadio.cpp b/src/platform/portduino/SimRadio.cpp index eb970df48..d0f2f1140 100644 --- a/src/platform/portduino/SimRadio.cpp +++ b/src/platform/portduino/SimRadio.cpp @@ -209,6 +209,8 @@ void SimRadio::startSend(meshtastic_MeshPacket *txp) isReceiving = false; size_t numbytes = beginSending(txp); meshtastic_MeshPacket *p = packetPool.allocCopy(*txp); + if (!p) + return; // A packet we originate that's encrypted for someone else (a PKI DM, channel == 0) can't be // decrypted here. Attempting it only logs a spurious "no suitable channel" miss, and the @@ -361,6 +363,8 @@ void SimRadio::handleReceiveInterrupt() meshtastic_MeshPacket *mp = packetPool.allocCopy(*receivingPacket); // keep a copy in packetPool packetPool.release(receivingPacket); // release the original receivingPacket = nullptr; + if (!mp) + return; printPacket("Lora RX", mp);