Browse Source

px4_daemon: fixes for packet length computation

The enum change from uint8_t to an int avoids uninitialized bytes,
which led to valgrind warnings (no error though).
sbg
Beat Küng 7 years ago committed by Lorenz Meier
parent
commit
5b171bd614
  1. 6
      platforms/posix/src/px4_daemon/client.cpp
  2. 2
      platforms/posix/src/px4_daemon/pipe_protocol.cpp
  3. 11
      platforms/posix/src/px4_daemon/pipe_protocol.h
  4. 2
      platforms/posix/src/px4_daemon/pxh.cpp

6
platforms/posix/src/px4_daemon/client.cpp

@ -165,7 +165,7 @@ Client::_send_cmds(const int argc, const char **argv) @@ -165,7 +165,7 @@ Client::_send_cmds(const int argc, const char **argv)
strcpy((char *)packet.payload.execute_msg.cmd, cmd_buf.c_str());
// The size is +1 because we want to include the null termination.
packet.header.payload_length = cmd_buf.size() + 1;
packet.header.payload_length = cmd_buf.size() + 1 + sizeof(packet.payload.execute_msg.is_atty);
_client_send_pipe_fd = open(get_client_send_pipe_path(_instance_id).c_str(), O_WRONLY);
@ -214,7 +214,7 @@ Client::_listen() @@ -214,7 +214,7 @@ Client::_listen()
// Again, we only read as much as we need because otherwise we need
// hold a buffer and parse it.
bytes_read = read(client_recv_pipe_fd, (char *)&packet_recv + bytes_read, payload_to_read);
bytes_read = read(client_recv_pipe_fd, ((uint8_t *)&packet_recv) + bytes_read, payload_to_read);
if (bytes_read > 0) {
@ -293,7 +293,7 @@ Client::_stdout_msg_packet(const client_recv_packet_s &packet) @@ -293,7 +293,7 @@ Client::_stdout_msg_packet(const client_recv_packet_s &packet)
return 0;
} else {
PX4_ERR("payload size wrong");
PX4_ERR("payload size wrong (%i > %i)", packet.header.payload_length, sizeof(packet.payload.stdout_msg.text));
return -1;
}
}

2
platforms/posix/src/px4_daemon/pipe_protocol.cpp

@ -53,7 +53,7 @@ namespace px4_daemon @@ -53,7 +53,7 @@ namespace px4_daemon
unsigned get_client_send_packet_length(const client_send_packet_s *packet)
{
return sizeof(client_send_packet_s) - sizeof(packet->payload) + packet->header.payload_length + sizeof(uint8_t);
return sizeof(client_send_packet_s) - sizeof(packet->payload) + packet->header.payload_length;
}
unsigned get_client_recv_packet_length(const client_recv_packet_s *packet)

11
platforms/posix/src/px4_daemon/pipe_protocol.h

@ -46,13 +46,16 @@ namespace px4_daemon @@ -46,13 +46,16 @@ namespace px4_daemon
static const unsigned RECV_PIPE_PATH_LEN = 64;
// The packet size is no more than 512 bytes, because that is the minimum guaranteed size
// for a pipe to avoid interleaving of messages when multiple clients write at the same time
// (atomic writes).
struct client_send_packet_s {
struct message_header_s {
enum class e_msg_id : uint8_t {
uint64_t client_uuid;
enum class e_msg_id : int {
EXECUTE,
KILL
} msg_id;
uint64_t client_uuid;
unsigned payload_length;
} header;
@ -70,7 +73,7 @@ struct client_send_packet_s { @@ -70,7 +73,7 @@ struct client_send_packet_s {
// We have per client receiver a pipe with the uuid in its file path.
struct client_recv_packet_s {
struct message_header_s {
enum class e_msg_id : uint8_t {
enum class e_msg_id : int {
RETVAL,
STDOUT
} msg_id;
@ -82,7 +85,7 @@ struct client_recv_packet_s { @@ -82,7 +85,7 @@ struct client_recv_packet_s {
int retval;
} retval_msg;
struct stdout_msg_s {
uint8_t text[512 - sizeof(message_header_s)];
uint8_t text[512 - sizeof(message_header_s)]; ///< null-terminated string (payload_length includes the null)
} stdout_msg;
} payload;
};

2
platforms/posix/src/px4_daemon/pxh.cpp

@ -239,8 +239,6 @@ void Pxh::run_pxh() @@ -239,8 +239,6 @@ void Pxh::run_pxh()
}
}
return;
}
void Pxh::stop()

Loading…
Cancel
Save