GCS_MAVLink: do not send FTP reply bytes which mean nothing

The whole reply buffer went out whatever the reply's size, so a short
reply was padded with bytes which are not part of it.

Those bytes come from the same reply, not an earlier one: setup_reply()
clears the whole transaction, but list_dir()'s offset-skip loop then
formats each entry it skips into response.data as scratch, and a listing
which ends in an EndOfFile NAK sets only data[0] - leaving the last
skipped entry sitting behind the error code.

Copy only the bytes the reply says it has. The rest of the packet is
already zero, and since MAVLink 2 trims trailing zeros from a payload, a
short reply now goes out shorter as well.

The scratch reuse behind it is left as it is; not sending the bytes is
what keeps them off the air.
This commit is contained in:
Peter Barker
2026-09-12 15:00:50 +10:00
committed by Andrew Tridgell
parent 14c871f273
commit 94726509fc
+3 -1
View File
@@ -120,7 +120,9 @@ bool GCS_FTP::send_reply(const Transaction &reply)
payload[5] = static_cast<uint8_t>(reply.req_opcode);
payload[6] = reply.burst_complete ? 1 : 0;
put_le32_ptr(&payload[8], reply.offset);
memcpy(&pkt.payload[12], reply.data, sizeof(reply.data));
// only the first size bytes belong to this reply; the packet is zeroed,
// so copying just those leaves the rest of it zero
memcpy(&pkt.payload[12], reply.data, MIN(reply.size, sizeof(reply.data)));
mavlink_msg_file_transfer_protocol_send_struct(reply.chan, &pkt);
return true;
}