Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoftEther: fix two heap-buffer-overflows #1695

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/lib/protocols/softether.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static size_t dissect_softether_type(enum softether_value_type t,

v->value.ptr.raw = payload + 4;
u_int32_t siz = ntohl(get_u_int32_t(payload, 0));
if(payload_len < siz + 3)
if(siz == 0 || payload_len < siz + 3)
return 0;

if(t == VALUE_DATA)
Expand Down Expand Up @@ -263,9 +263,6 @@ static int dissect_softether_ip_port(struct ndpi_flow_struct *flow,
if(ip_port_separator == NULL)
return 1;

if(ip_port_separator < (char const *)packet->payload + NDPI_STATICSTRING_LEN("IP="))
return 1;

ip_len = ndpi_min(sizeof(flow->protos.softether.ip) - 1,
ip_port_separator - (char const *)packet->payload -
NDPI_STATICSTRING_LEN("IP="));
Expand All @@ -275,16 +272,14 @@ static int dissect_softether_ip_port(struct ndpi_flow_struct *flow,
ip_len);
flow->protos.softether.ip[ip_len] = '\0';

if(ip_port_separator < (char const *)packet->payload +
NDPI_STATICSTRING_LEN("IP=") + NDPI_STATICSTRING_LEN(",PORT="))
return 1;
if (packet->payload_packet_len < (ip_port_separator - (char const *)packet->payload) +
NDPI_STATICSTRING_LEN(",PORT="))
return 1;

port_len = ndpi_min(sizeof(flow->protos.softether.port) - 1,
ip_port_separator - (char const *)packet->payload -
NDPI_STATICSTRING_LEN("IP=") - NDPI_STATICSTRING_LEN(",PORT="));

strncpy(flow->protos.softether.port,
ip_port_separator + NDPI_STATICSTRING_LEN(",PORT="),
packet->payload_packet_len - (ip_port_separator - (char const *)packet->payload) -
NDPI_STATICSTRING_LEN(",PORT="));
strncpy(flow->protos.softether.port, ip_port_separator + NDPI_STATICSTRING_LEN(",PORT="),
port_len);

flow->protos.softether.port[port_len] = '\0';
Expand Down