Skip to content

Commit

Permalink
Don't return local strings from proto filterchecks
Browse files Browse the repository at this point in the history
These were returning pointers to local string values on the
stack. Replace with m_tstr, a general purpose string in the object,
instead.
  • Loading branch information
mstemm committed Aug 21, 2018
1 parent d134f3a commit c8db291
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions userspace/libsinsp/filterchecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,20 +773,20 @@ uint8_t* sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT uint32_t* len, bool

if(m_fdinfo->is_role_none())
{
return NULL;
RETURN_EXTRACT_CSTR("None");
}

string port = "";
m_tstr = "";
if(evt_type == SCAP_FD_IPV4_SOCK)
{
port = port_to_string(m_fdinfo->m_sockinfo.m_ipv4info.m_fields.m_sport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
m_tstr = port_to_string(m_fdinfo->m_sockinfo.m_ipv4info.m_fields.m_sport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
}
else if(evt_type == SCAP_FD_IPV6_SOCK)
{
port = port_to_string(m_fdinfo->m_sockinfo.m_ipv6info.m_fields.m_sport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
m_tstr = port_to_string(m_fdinfo->m_sockinfo.m_ipv6info.m_fields.m_sport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
}

RETURN_EXTRACT_STRING(port);
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_SERVERPORT:
{
Expand Down Expand Up @@ -868,17 +868,17 @@ uint8_t* sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT uint32_t* len, bool
return NULL;
}

string port = "";
m_tstr = "";
if(evt_type == SCAP_FD_IPV4_SOCK)
{
port = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
m_tstr = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
}
else if(evt_type == SCAP_FD_IPV6_SOCK)
{
port = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
m_tstr = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
}

RETURN_EXTRACT_STRING(port);
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_LPORT:
case TYPE_RPORT:
Expand Down Expand Up @@ -1049,9 +1049,8 @@ uint8_t* sinsp_filter_check_fd::extract(sinsp_evt *evt, OUT uint32_t* len, bool
}
}

string port = "";
port = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
RETURN_EXTRACT_STRING(port);
m_tstr = port_to_string(nport, this->m_fdinfo->get_l4proto(), m_inspector->m_hostname_and_port_resolution_enabled);
RETURN_EXTRACT_STRING(m_tstr);
}

case TYPE_L4PROTO:
Expand Down

0 comments on commit c8db291

Please sign in to comment.