Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/FSCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ std::vector<meshtastic_FileInfo> getFiles(const char *dirname, uint8_t levels)
} else {
meshtastic_FileInfo fileInfo = {"", static_cast<uint32_t>(file.size())};
#ifdef ARCH_ESP32
strcpy(fileInfo.file_name, file.path());
strncpy(fileInfo.file_name, file.path(), sizeof(fileInfo.file_name) - 1);
fileInfo.file_name[sizeof(fileInfo.file_name) - 1] = '\0';
#else
strcpy(fileInfo.file_name, file.name());
strncpy(fileInfo.file_name, file.name(), sizeof(fileInfo.file_name) - 1);
fileInfo.file_name[sizeof(fileInfo.file_name) - 1] = '\0';
#endif
if (!String(fileInfo.file_name).endsWith(".")) {
filenames.push_back(fileInfo);
Expand Down
9 changes: 6 additions & 3 deletions src/RedirectablePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ void RedirectablePrint::log_to_ble(const char *logLevel, const char *format, va_
auto thread = concurrency::OSThread::currentThread;
meshtastic_LogRecord logRecord = meshtastic_LogRecord_init_zero;
logRecord.level = getLogLevel(logLevel);
strcpy(logRecord.message, message);
if (thread)
strcpy(logRecord.source, thread->ThreadName.c_str());
strncpy(logRecord.message, message, sizeof(logRecord.message) - 1);
logRecord.message[sizeof(logRecord.message) - 1] = '\0';
if (thread) {
strncpy(logRecord.source, thread->ThreadName.c_str(), sizeof(logRecord.source) - 1);
logRecord.source[sizeof(logRecord.source) - 1] = '\0';
}
logRecord.time = getValidTime(RTCQuality::RTCQualityDevice, true);

uint8_t *buffer = new uint8_t[meshtastic_LogRecord_size];
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ bool NodeDB::updateUser(uint32_t nodeId, meshtastic_User &p, uint8_t channelInde
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
cn->level = meshtastic_LogRecord_Level_WARNING;
cn->time = getValidTime(RTCQualityFromNet);
sprintf(cn->message, warning, p.long_name);
snprintf(cn->message, sizeof(cn->message), warning, p.long_name);
service->sendClientNotification(cn);
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/DetectionSensorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void DetectionSensorModule::sendDetectionMessage()
{
LOG_DEBUG("Detected event observed. Send message");
char *message = new char[40];
sprintf(message, "%s detected", moduleConfig.detection_sensor.name);
snprintf(message, 40, "%s detected", moduleConfig.detection_sensor.name);
meshtastic_MeshPacket *p = allocDataPacket();
p->want_ack = false;
p->decoded.payload.size = strlen(message);
Expand All @@ -142,7 +142,7 @@ void DetectionSensorModule::sendDetectionMessage()
void DetectionSensorModule::sendCurrentStateMessage(bool state)
{
char *message = new char[40];
sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state);
snprintf(message, 40, "%s state: %i", moduleConfig.detection_sensor.name, state);
meshtastic_MeshPacket *p = allocDataPacket();
p->want_ack = false;
p->decoded.payload.size = strlen(message);
Expand Down
10 changes: 5 additions & 5 deletions src/modules/DropzoneModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ 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);
snprintf(matchCompare, sizeof(matchCompare), "%s conditions", owner.short_name);
if (strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
LOG_DEBUG("Received dropzone conditions request");
startSendConditions = millis();
}

sprintf(matchCompare, "%s conditions", owner.long_name);
snprintf(matchCompare, sizeof(matchCompare), "%s conditions", owner.long_name);
if (strncasecmp(incomingMessage, matchCompare, strlen(matchCompare)) == 0) {
LOG_DEBUG("Received dropzone conditions request");
startSendConditions = millis();
Expand Down Expand Up @@ -77,11 +77,11 @@ meshtastic_MeshPacket *DropzoneModule::sendConditions()
auto windDirection = telemetry.variant.environment_metrics.wind_direction;
auto temp = telemetry.variant.environment_metrics.temperature;
auto baro = UnitConversions::HectoPascalToInchesOfMercury(telemetry.variant.environment_metrics.barometric_pressure);
sprintf(replyStr, "%s @ %02d:%02d:%02dz\nWind %.2f kts @ %d°\nBaro %.2f inHg %.2f°C", dropzoneStatus, hour, min, sec,
windSpeed, windDirection, baro, temp);
snprintf(replyStr, sizeof(replyStr), "%s @ %02d:%02d:%02dz\nWind %.2f kts @ %d°\nBaro %.2f inHg %.2f°C", dropzoneStatus,
hour, min, sec, windSpeed, windDirection, baro, temp);
} else {
LOG_ERROR("No sensor found");
sprintf(replyStr, "%s @ %02d:%02d:%02d\nNo sensor found", dropzoneStatus, hour, min, sec);
snprintf(replyStr, sizeof(replyStr), "%s @ %02d:%02d:%02d\nNo sensor found", dropzoneStatus, hour, min, sec);
}
LOG_DEBUG("Conditions reply: %s", replyStr);
reply->decoded.payload.size = strlen(replyStr); // You must specify how many bytes are in the reply
Expand Down
12 changes: 6 additions & 6 deletions src/modules/KeyVerificationModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ 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");
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;
strncpy(cn->payload_variant.key_verification_number_request.remote_longname, // should really check for nulls, etc
Expand All @@ -83,7 +83,7 @@ bool KeyVerificationModule::handleReceivedProtobuf(const meshtastic_MeshPacket &
} else if (currentState == KEY_VERIFICATION_RECEIVER_AWAITING_HASH1 && r->hash1.size == 32 && r->nonce == currentNonce) {
if (memcmp(hash1, r->hash1.bytes, 32) == 0) {
memset(message, 0, sizeof(message));
sprintf(message, "Verification: \n");
snprintf(message, sizeof(message), "Verification: \n");
generateVerificationCode(message + 15);
LOG_INFO("Hash1 matches!");
static const char *optionsArray[] = {"Reject", "Accept"};
Expand All @@ -101,7 +101,7 @@ 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);
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;
strncpy(cn->payload_variant.key_verification_final.remote_longname, // should really check for nulls, etc
Expand Down Expand Up @@ -198,8 +198,8 @@ meshtastic_MeshPacket *KeyVerificationModule::allocReply()
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);
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;
strncpy(cn->payload_variant.key_verification_number_inform.remote_longname, // should really check for nulls, etc
Expand Down Expand Up @@ -262,7 +262,7 @@ void KeyVerificationModule::processSecurityNumber(uint32_t incomingNumber)
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);
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;
strncpy(cn->payload_variant.key_verification_final.remote_longname, // should really check for nulls, etc
Expand Down
3 changes: 2 additions & 1 deletion src/modules/NodeInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ meshtastic_MeshPacket *NodeInfoModule::allocReply()
// u.id[0] = '\0';

// Ensure our user.id is derived correctly
strcpy(u.id, nodeDB->getNodeId().c_str());
strncpy(u.id, nodeDB->getNodeId().c_str(), sizeof(u.id) - 1);
u.id[sizeof(u.id) - 1] = '\0';

LOG_INFO("Send owner %s/%s/%s", u.id, u.long_name, u.short_name);
lastSentToMesh = millis();
Expand Down
Loading