From 1d659cb1de49982fe7aa3a0ed0f885e1485af858 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 24 Nov 2018 09:41:21 +0100 Subject: [PATCH] Add protection to malformed time entry --- src/core/receiver/tcp_cmd_interface.cc | 71 ++++++++++++++------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/core/receiver/tcp_cmd_interface.cc b/src/core/receiver/tcp_cmd_interface.cc index 9d3591488..ecb175e5f 100644 --- a/src/core/receiver/tcp_cmd_interface.cc +++ b/src/core/receiver/tcp_cmd_interface.cc @@ -35,6 +35,35 @@ #include +TcpCmdInterface::TcpCmdInterface() +{ + register_functions(); + keep_running_ = true; + control_queue_ = nullptr; + rx_latitude_ = 0; + rx_longitude_ = 0; + rx_altitude_ = 0; + receiver_utc_time_ = 0; +} + + +TcpCmdInterface::~TcpCmdInterface() +{ +} + + +void TcpCmdInterface::register_functions() +{ + functions["status"] = std::bind(&TcpCmdInterface::status, this, std::placeholders::_1); + functions["standby"] = std::bind(&TcpCmdInterface::standby, this, std::placeholders::_1); + functions["reset"] = std::bind(&TcpCmdInterface::reset, this, std::placeholders::_1); + functions["hotstart"] = std::bind(&TcpCmdInterface::hotstart, this, std::placeholders::_1); + functions["warmstart"] = std::bind(&TcpCmdInterface::warmstart, this, std::placeholders::_1); + functions["coldstart"] = std::bind(&TcpCmdInterface::coldstart, this, std::placeholders::_1); + functions["set_ch_satellite"] = std::bind(&TcpCmdInterface::set_ch_satellite, this, std::placeholders::_1); +} + + void TcpCmdInterface::set_pvt(std::shared_ptr PVT_sptr) { PVT_sptr_ = PVT_sptr; @@ -145,7 +174,11 @@ std::string TcpCmdInterface::hotstart(const std::vector &commandLin { // Read commandline time parameter struct tm tm; - strptime(commandLine.at(1).c_str(), "%d/%m/%Y %H:%M:%S", &tm); + if (strptime(commandLine.at(1).c_str(), "%d/%m/%Y %H:%M:%S", &tm) == nullptr) + { + response = "ERROR: time parameter malformed\n"; + return response; + } receiver_utc_time_ = timegm(&tm); // Read latitude, longitude, and height @@ -188,7 +221,11 @@ std::string TcpCmdInterface::warmstart(const std::vector &commandLi // Read commandline time parameter struct tm tm; tmp_str = commandLine.at(1) + commandLine.at(2); - strptime(tmp_str.c_str(), "%d/%m/%Y %H:%M:%S", &tm); + if (strptime(commandLine.at(1).c_str(), "%d/%m/%Y %H:%M:%S", &tm) == nullptr) + { + response = "ERROR: time parameter malformed\n"; + return response; + } receiver_utc_time_ = timegm(&tm); // Read latitude, longitude, and height @@ -247,30 +284,6 @@ std::string TcpCmdInterface::set_ch_satellite(const std::vector &co } -void TcpCmdInterface::register_functions() -{ - functions["status"] = std::bind(&TcpCmdInterface::status, this, std::placeholders::_1); - functions["standby"] = std::bind(&TcpCmdInterface::standby, this, std::placeholders::_1); - functions["reset"] = std::bind(&TcpCmdInterface::reset, this, std::placeholders::_1); - functions["hotstart"] = std::bind(&TcpCmdInterface::hotstart, this, std::placeholders::_1); - functions["warmstart"] = std::bind(&TcpCmdInterface::warmstart, this, std::placeholders::_1); - functions["coldstart"] = std::bind(&TcpCmdInterface::coldstart, this, std::placeholders::_1); - functions["set_ch_satellite"] = std::bind(&TcpCmdInterface::set_ch_satellite, this, std::placeholders::_1); -} - - -TcpCmdInterface::TcpCmdInterface() -{ - register_functions(); - keep_running_ = true; - control_queue_ = nullptr; - rx_latitude_ = 0; - rx_longitude_ = 0; - rx_altitude_ = 0; - receiver_utc_time_ = 0; -} - - void TcpCmdInterface::set_msg_queue(gr::msg_queue::sptr control_queue) { control_queue_ = control_queue; @@ -385,9 +398,3 @@ void TcpCmdInterface::run_cmd_server(int tcp_port) std::cout << "TCP Command Interface exception: address already in use" << std::endl; } } - - -TcpCmdInterface::~TcpCmdInterface() -{ - // TODO Auto-generated destructor stub -}