Browse Source

Plane: prevent integer underflow with comm_get_txspace()

master
Andrew Tridgell 11 years ago
parent
commit
fe3c51d516
  1. 5
      ArduPlane/Attitude.pde
  2. 8
      ArduPlane/GCS_Mavlink.pde

5
ArduPlane/Attitude.pde

@ -874,10 +874,11 @@ static void set_servos(void)
// OBC rules // OBC rules
obc.check_crash_plane(); obc.check_crash_plane();
#endif #endif
#if HIL_MODE != HIL_MODE_DISABLED #if HIL_MODE != HIL_MODE_DISABLED
// get the servos to the GCS immediately for HIL // get the servos to the GCS immediately for HIL
if (comm_get_txspace(MAVLINK_COMM_0) - MAVLINK_NUM_NON_PAYLOAD_BYTES >= MAVLINK_MSG_ID_RC_CHANNELS_SCALED_LEN) { if (comm_get_txspace(MAVLINK_COMM_0) >=
MAVLINK_MSG_ID_RC_CHANNELS_SCALED_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) {
send_servo_out(MAVLINK_COMM_0); send_servo_out(MAVLINK_COMM_0);
} }
if (!g.hil_servos) { if (!g.hil_servos) {

8
ArduPlane/GCS_Mavlink.pde

@ -9,9 +9,6 @@ static bool in_mavlink_delay;
// true if we are out of time in our event timeslice // true if we are out of time in our event timeslice
static bool gcs_out_of_time; static bool gcs_out_of_time;
// check if a message will fit in the payload space available
#define CHECK_PAYLOAD_SIZE(id) if (payload_space < MAVLINK_MSG_ID_ ## id ## _LEN) return false
/* /*
* !!NOTE!! * !!NOTE!!
* *
@ -480,11 +477,14 @@ static bool telemetry_delayed(mavlink_channel_t chan)
return true; return true;
} }
// check if a message will fit in the payload space available
#define CHECK_PAYLOAD_SIZE(id) if (txspace < MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_ ## id ## _LEN) return false
// try to send a message, return false if it won't fit in the serial tx buffer // try to send a message, return false if it won't fit in the serial tx buffer
bool GCS_MAVLINK::try_send_message(enum ap_message id) bool GCS_MAVLINK::try_send_message(enum ap_message id)
{ {
int16_t payload_space = comm_get_txspace(chan) - MAVLINK_NUM_NON_PAYLOAD_BYTES; uint16_t txspace = comm_get_txspace(chan);
if (telemetry_delayed(chan)) { if (telemetry_delayed(chan)) {
return false; return false;

Loading…
Cancel
Save