Skip to content

Commit

Permalink
core: make udpin parsing stricter
Browse files Browse the repository at this point in the history
We don't want to accept udpin://:PORT but we always
need the network interface, e.g.:
- udpin://192.168.X.Y:PORT, or
- udpin://0.0.0.0:PORT for all network interfaces

Without this we got an error further down with inet_pton.
  • Loading branch information
julianoes committed Oct 15, 2024
1 parent ea06648 commit a42897c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mavsdk/core/cli_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ bool CliArg::parse_udpin(const std::string_view rest)
auto& p = std::get<Udp>(protocol);
p.host = rest.substr(0, pos);
p.mode = Udp::Mode::In;
p.host = rest.substr(0, pos);
p.mode = Udp::Mode::In;

if (p.host.empty()) {
LogErr() << "No network interface (or 0.0.0.0 for all network interfaces) supplied";
return false;
}

if (auto maybe_port = port_from_str(rest.substr(pos + 1))) {
p.port = maybe_port.value();
Expand Down
7 changes: 7 additions & 0 deletions src/mavsdk/core/cli_arg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ TEST(CliArg, UdpInAll)
EXPECT_EQ(udp->mode, CliArg::Udp::Mode::In);
}

TEST(CliArg, UdpInWrong)
{
CliArg ca;

EXPECT_FALSE(ca.parse("udpin://:55"));
}

TEST(CliArg, UdpInSpecific)
{
CliArg ca;
Expand Down

0 comments on commit a42897c

Please sign in to comment.