bisdn / basebox

A tiny OpenFlow controller for OF-DPA switches.
Mozilla Public License 2.0
45 stars 9 forks source link

do not call std::string_view() with NULL pointer as argument #308

Closed akoepsel closed 3 years ago

akoepsel commented 3 years ago

Description

In cnetlink.cc line 1075 the VLOG call must not call std::string_view(NULL). Added two checks to prevent a situation where calling rtnl_link_get_type() or rtnl_link_get_slave_type() yield a NULL pointer, inevitably causing an exception.

Motivation and Context

How Has This Been Tested?

rubensfig commented 3 years ago

I have changed the branch to next, to prepare for the merges.

@KanjiMonster could you please add your comment from #306 here as well?

KanjiMonster commented 3 years ago

I don't think not logging is the right solution.

Maybe we can have a helper function something like

std::string_view safe_string_view(const char *str)
{
  if (str == nullptr)
    return std::string_view("(null)");
  else
    return std::string_view(str);
}

and then use this everywhere where we might have a null pointer? This would replicate printf's behavior when passing NULL to a %s.

Finally, let's maybe have only one PR for this.

jklare commented 3 years ago

is this still being worked on?