From c9f6e12d60717f584a4c9f1e764a4a45cddc3c40 Mon Sep 17 00:00:00 2001 From: "tridge60@gmail.com" Date: Thu, 3 Mar 2011 11:40:19 +0000 Subject: [PATCH] mavlink: fixed parameter string handling this prevents running past the end of a non-terminated string. git-svn-id: https://arducopter.googlecode.com/svn/trunk@1740 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- ArduCopterMega/GCS_Mavlink.pde | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ArduCopterMega/GCS_Mavlink.pde b/ArduCopterMega/GCS_Mavlink.pde index 1a1d7cc72a..a1c02ec647 100644 --- a/ArduCopterMega/GCS_Mavlink.pde +++ b/ArduCopterMega/GCS_Mavlink.pde @@ -551,7 +551,10 @@ void GCS_MAVLINK::handleMessage(mavlink_message_t* msg) break; // set parameter - const char * key = (const char*) packet.param_id; + + char key[ONBOARD_PARAM_NAME_LENGTH+1]; + strncpy(key, (char *)packet.param_id, ONBOARD_PARAM_NAME_LENGTH); + key[ONBOARD_PARAM_NAME_LENGTH] = 0; // find the requested parameter vp = AP_Var::find(key); @@ -581,13 +584,9 @@ void GCS_MAVLINK::handleMessage(mavlink_message_t* msg) } // Report back new value - char param_name[ONBOARD_PARAM_NAME_LENGTH]; // XXX HACK - need something to return a char * - vp->copy_name(param_name, sizeof(param_name)); - mavlink_msg_param_value_send(chan, - (int8_t*)param_name, - packet.param_value, - _count_parameters(), - -1); // XXX we don't actually know what its index is... + mavlink_msg_param_value_send(chan, (int8_t *)key, packet.param_value, + _count_parameters(), + -1); // XXX we don't actually know what its index is... break; } // end case