1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-23 01:49:53 +03:00

Merge PR #718: src/Cedar/BridgeUnix.c: resolve null pointer dereference

This commit is contained in:
Davide Beatrici 2018-09-29 23:30:28 +02:00 committed by GitHub
commit 34f443c0c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 105 deletions

View File

@ -2674,6 +2674,7 @@ bool EthProcessIpPacketInnerIpRaw(ETH *e, PKT *p)
void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size) void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
{ {
PKT *p; PKT *p;
SOCK *s = NULL;
// Validate arguments // Validate arguments
if (e == NULL || data == NULL) if (e == NULL || data == NULL)
{ {
@ -2686,8 +2687,13 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
} }
p = ParsePacket(data, size); p = ParsePacket(data, size);
if (p == NULL)
{
Free(data);
return;
}
if (p != NULL && (p->BroadcastPacket || Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) == 0)) if (p->BroadcastPacket || Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) == 0)
{ {
if (IsValidUnicastMacAddress(p->MacAddressSrc)) if (IsValidUnicastMacAddress(p->MacAddressSrc))
{ {
@ -2703,93 +2709,88 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
return; return;
} }
if (p != NULL)
if (p->TypeL3 == L3_IPV4)
{ {
SOCK *s = NULL; if (p->TypeL4 == L4_TCP)
if (p->TypeL3 == L3_IPV4)
{ {
if (p->TypeL4 == L4_TCP) if (IsZeroIP(&e->MyPhysicalIP) == false)
{ {
if (IsZeroIP(&e->MyPhysicalIP) == false) s = e->RawTcp;
{
s = e->RawTcp;
}
}
else if (p->TypeL4 == L4_UDP)
{
if (EthProcessIpPacketInnerIpRaw(e, p) == false)
{
s = e->RawUdp;
}
}
else if (p->TypeL4 == L4_ICMPV4)
{
if (IsZeroIP(&e->MyPhysicalIP) == false)
{
s = e->RawIcmp;
}
}
else if (p->TypeL4 == L4_FRAGMENT)
{
if (IsZeroIP(&e->MyPhysicalIP) == false)
{
s = e->RawIcmp;
}
} }
} }
else if (p->TypeL3 == L3_ARPV4) else if (p->TypeL4 == L4_UDP)
{ {
EthProcessIpPacketInnerIpRaw(e, p); if (EthProcessIpPacketInnerIpRaw(e, p) == false)
}
if (s != NULL && p->L3.IPv4Header->DstIP != 0xffffffff && p->BroadcastPacket == false &&
p->L3.IPv4Header->SrcIP == IPToUINT(&e->YourIP))
{
UCHAR *send_data = p->IPv4PayloadData;
UCHAR *head = p->PacketData;
UINT remove_header_size = (UINT)(send_data - head);
if (p->PacketSize > remove_header_size)
{ {
IP dest; s = e->RawUdp;
UINT send_data_size = p->PacketSize - remove_header_size;
// checksum
if (p->TypeL4 == L4_UDP)
{
p->L4.UDPHeader->Checksum = 0;
}
else if (p->TypeL4 == L4_TCP)
{
p->L4.TCPHeader->Checksum = 0;
p->L4.TCPHeader->Checksum = CalcChecksumForIPv4(IPToUINT(&e->MyPhysicalIP),
p->L3.IPv4Header->DstIP, IP_PROTO_TCP,
p->L4.TCPHeader, p->IPv4PayloadSize, 0);
}
UINTToIP(&dest, p->L3.IPv4Header->DstIP);
if (s->RawIP_HeaderIncludeFlag == false)
{
SendTo(s, &dest, 0, send_data, send_data_size);
}
else
{
IPV4_HEADER *ip = p->L3.IPv4Header;
ip->SrcIP = IPToUINT(&e->MyPhysicalIP);
ip->Checksum = 0;
ip->Checksum = IpChecksum(ip, IPV4_GET_HEADER_LEN(ip) * 4);
SendTo(s, &dest, 0, ip, ((UCHAR *)p->PacketData - (UCHAR *)ip) + p->PacketSize);
}
} }
} }
else if (p->TypeL4 == L4_ICMPV4)
FreePacket(p); {
if (IsZeroIP(&e->MyPhysicalIP) == false)
{
s = e->RawIcmp;
}
}
else if (p->TypeL4 == L4_FRAGMENT)
{
if (IsZeroIP(&e->MyPhysicalIP) == false)
{
s = e->RawIcmp;
}
}
}
else if (p->TypeL3 == L3_ARPV4)
{
EthProcessIpPacketInnerIpRaw(e, p);
} }
if (s != NULL && p->L3.IPv4Header->DstIP != 0xffffffff && p->BroadcastPacket == false &&
p->L3.IPv4Header->SrcIP == IPToUINT(&e->YourIP))
{
UCHAR *send_data = p->IPv4PayloadData;
UCHAR *head = p->PacketData;
UINT remove_header_size = (UINT)(send_data - head);
if (p->PacketSize > remove_header_size)
{
IP dest;
UINT send_data_size = p->PacketSize - remove_header_size;
// checksum
if (p->TypeL4 == L4_UDP)
{
p->L4.UDPHeader->Checksum = 0;
}
else if (p->TypeL4 == L4_TCP)
{
p->L4.TCPHeader->Checksum = 0;
p->L4.TCPHeader->Checksum = CalcChecksumForIPv4(IPToUINT(&e->MyPhysicalIP),
p->L3.IPv4Header->DstIP, IP_PROTO_TCP,
p->L4.TCPHeader, p->IPv4PayloadSize, 0);
}
UINTToIP(&dest, p->L3.IPv4Header->DstIP);
if (s->RawIP_HeaderIncludeFlag == false)
{
SendTo(s, &dest, 0, send_data, send_data_size);
}
else
{
IPV4_HEADER *ip = p->L3.IPv4Header;
ip->SrcIP = IPToUINT(&e->MyPhysicalIP);
ip->Checksum = 0;
ip->Checksum = IpChecksum(ip, IPV4_GET_HEADER_LEN(ip) * 4);
SendTo(s, &dest, 0, ip, ((UCHAR *)p->PacketData - (UCHAR *)ip) + p->PacketSize);
}
}
}
FreePacket(p);
Free(data); Free(data);
} }

View File

@ -315,14 +315,7 @@ UINT Count(COUNTER *c)
Lock(c->lock); Lock(c->lock);
{ {
if (c->Ready == false) ret = c->c;
{
ret = 0;
}
else
{
ret = c->c;
}
} }
Unlock(c->lock); Unlock(c->lock);
@ -345,15 +338,8 @@ UINT Inc(COUNTER *c)
Lock(c->lock); Lock(c->lock);
{ {
if (c->Ready == false) c->c++;
{ ret = c->c;
ret = 0;
}
else
{
c->c++;
ret = c->c;
}
} }
Unlock(c->lock); Unlock(c->lock);
@ -380,21 +366,14 @@ UINT Dec(COUNTER *c)
Lock(c->lock); Lock(c->lock);
{ {
if (c->Ready == false) if (c->c != 0)
{ {
ret = 0; c->c--;
ret = c->c;
} }
else else
{ {
if (c->c != 0) ret = 0;
{
c->c--;
ret = c->c;
}
else
{
ret = 0;
}
} }
} }
Unlock(c->lock); Unlock(c->lock);