mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-28 09:54:51 +00:00
Add protection to malformed time entry
This commit is contained in:
parent
144269a268
commit
1d659cb1de
@ -35,6 +35,35 @@
|
||||
#include <sstream>
|
||||
|
||||
|
||||
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<PvtInterface> PVT_sptr)
|
||||
{
|
||||
PVT_sptr_ = PVT_sptr;
|
||||
@ -145,7 +174,11 @@ std::string TcpCmdInterface::hotstart(const std::vector<std::string> &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<std::string> &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<std::string> &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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user