Make sure host_metrics user_string is null terminated

This commit is contained in:
Jonathan Bennett
2025-06-17 11:11:36 -05:00
parent aabc5b7cf2
commit 3ab9005b2f

View File

@@ -111,7 +111,8 @@ meshtastic_Telemetry HostMetricsModule::getHostMetrics()
if (settingsStrings[hostMetrics_user_command] != "") {
std::string userCommandResult = exec(settingsStrings[hostMetrics_user_command].c_str());
if (userCommandResult.length() > 1) {
strncpy(t.variant.host_metrics.user_string, userCommandResult.c_str(), 200);
strncpy(t.variant.host_metrics.user_string, userCommandResult.c_str(), sizeof(t.variant.host_metrics.user_string));
t.variant.host_metrics.user_string[ sizeof(t.variant.host_metrics.user_string) - 1] = '\0';
t.variant.host_metrics.has_user_string = true;
}
}