mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-22 17:39:53 +03:00
Merge PR #658: resolve several issues found by coverity
This commit is contained in:
commit
5f120e3c5e
@ -2312,10 +2312,6 @@ PPP_LCP *ParseLCP(USHORT protocol, void *data, UINT size)
|
|||||||
c->OptionList = NewListFast(NULL);
|
c->OptionList = NewListFast(NULL);
|
||||||
|
|
||||||
// Code
|
// Code
|
||||||
if (size < 1)
|
|
||||||
{
|
|
||||||
goto LABEL_ERROR;
|
|
||||||
}
|
|
||||||
c->Code = buf[0];
|
c->Code = buf[0];
|
||||||
buf++;
|
buf++;
|
||||||
size--;
|
size--;
|
||||||
@ -2655,18 +2651,6 @@ void MsChapV2Server_GenerateChallenge(UCHAR *dst)
|
|||||||
Rand(dst, 16);
|
Rand(dst, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the MS-CHAPv2 client-side challenge
|
|
||||||
void MsChapV2Client_GenerateChallenge(UCHAR *dst)
|
|
||||||
{
|
|
||||||
// Validate arguments
|
|
||||||
if (dst == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rand(dst, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a 8 bytes challenge
|
// Generate a 8 bytes challenge
|
||||||
void MsChapV2_GenerateChallenge8(UCHAR *dst, UCHAR *client_challenge, UCHAR *server_challenge, char *username)
|
void MsChapV2_GenerateChallenge8(UCHAR *dst, UCHAR *client_challenge, UCHAR *server_challenge, char *username)
|
||||||
{
|
{
|
||||||
|
@ -329,7 +329,6 @@ bool IsHubExistsWithLock(CEDAR *cedar, char *hubname);
|
|||||||
void GenerateNtPasswordHash(UCHAR *dst, char *password);
|
void GenerateNtPasswordHash(UCHAR *dst, char *password);
|
||||||
void GenerateNtPasswordHashHash(UCHAR *dst_hash, UCHAR *src_hash);
|
void GenerateNtPasswordHashHash(UCHAR *dst_hash, UCHAR *src_hash);
|
||||||
void MsChapV2Server_GenerateChallenge(UCHAR *dst);
|
void MsChapV2Server_GenerateChallenge(UCHAR *dst);
|
||||||
void MsChapV2Client_GenerateChallenge(UCHAR *dst);
|
|
||||||
void MsChapV2_GenerateChallenge8(UCHAR *dst, UCHAR *client_challenge, UCHAR *server_challenge, char *username);
|
void MsChapV2_GenerateChallenge8(UCHAR *dst, UCHAR *client_challenge, UCHAR *server_challenge, char *username);
|
||||||
void MsChapV2Client_GenerateResponse(UCHAR *dst, UCHAR *challenge8, UCHAR *nt_password_hash);
|
void MsChapV2Client_GenerateResponse(UCHAR *dst, UCHAR *challenge8, UCHAR *nt_password_hash);
|
||||||
void MsChapV2Server_GenerateResponse(UCHAR *dst, UCHAR *nt_password_hash_hash, UCHAR *client_response, UCHAR *challenge8);
|
void MsChapV2Server_GenerateResponse(UCHAR *dst, UCHAR *nt_password_hash_hash, UCHAR *client_response, UCHAR *challenge8);
|
||||||
|
@ -122,30 +122,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <Mayaqua/Mayaqua.h>
|
#include <Mayaqua/Mayaqua.h>
|
||||||
|
|
||||||
|
|
||||||
// Send an ICMP Echo
|
|
||||||
ICMP_RESULT *IcmpEchoSend(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout)
|
|
||||||
{
|
|
||||||
// Validate arguments
|
|
||||||
if (dest_ip == NULL || IsIP4(dest_ip) == false || (size != 0 && data == NULL))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (ttl == 0)
|
|
||||||
{
|
|
||||||
ttl = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsIcmpApiSupported())
|
|
||||||
{
|
|
||||||
return IcmpApiEchoSend(dest_ip, ttl, data, size, timeout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return IcmpEchoSendBySocket(dest_ip, ttl, data, size, timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Release the memory for the ICMP response
|
// Release the memory for the ICMP response
|
||||||
void IcmpFreeResult(ICMP_RESULT *r)
|
void IcmpFreeResult(ICMP_RESULT *r)
|
||||||
{
|
{
|
||||||
@ -271,138 +247,6 @@ ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the ICMP Echo (by a socket)
|
|
||||||
ICMP_RESULT *IcmpEchoSendBySocket(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout)
|
|
||||||
{
|
|
||||||
SOCK *s;
|
|
||||||
ICMP_RESULT *ret = NULL;
|
|
||||||
USHORT id;
|
|
||||||
USHORT seq;
|
|
||||||
UINT64 sent_tick;
|
|
||||||
UINT64 recv_tick;
|
|
||||||
// Validate arguments
|
|
||||||
if (dest_ip == NULL || IsIP4(dest_ip) == false || (size != 0 && data == NULL))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (ttl == 0)
|
|
||||||
{
|
|
||||||
ttl = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = NewUDP4(MAKE_SPECIAL_PORT(IP_PROTO_ICMPV4), NULL);
|
|
||||||
if (s != NULL)
|
|
||||||
{
|
|
||||||
// Construction of the ICMP packet
|
|
||||||
UCHAR *send_buffer;
|
|
||||||
UINT send_buffer_size = sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + size;
|
|
||||||
ICMP_HEADER *send_icmp_header;
|
|
||||||
ICMP_ECHO *send_icmp_echo;
|
|
||||||
UINT i;
|
|
||||||
|
|
||||||
id = Rand16();
|
|
||||||
if (id == 0)
|
|
||||||
{
|
|
||||||
id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
seq = Rand16();
|
|
||||||
if (seq == 0)
|
|
||||||
{
|
|
||||||
seq = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
send_buffer = ZeroMalloc(send_buffer_size);
|
|
||||||
|
|
||||||
send_icmp_header = (ICMP_HEADER *)send_buffer;
|
|
||||||
send_icmp_header->Type = ICMP_TYPE_ECHO_REQUEST;
|
|
||||||
|
|
||||||
send_icmp_echo = (ICMP_ECHO *)(send_buffer + sizeof(ICMP_HEADER));
|
|
||||||
send_icmp_echo->Identifier = Endian16(id);
|
|
||||||
send_icmp_echo->SeqNo = Endian16(seq);
|
|
||||||
|
|
||||||
Copy(send_buffer + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO), data, size);
|
|
||||||
|
|
||||||
send_icmp_header->Checksum = IpChecksum(send_buffer, send_buffer_size);
|
|
||||||
|
|
||||||
// Send an ICMP
|
|
||||||
SetTtl(s, ttl);
|
|
||||||
sent_tick = TickHighres64();
|
|
||||||
i = SendTo(s, dest_ip, MAKE_SPECIAL_PORT(IP_PROTO_ICMPV4), send_buffer, send_buffer_size);
|
|
||||||
|
|
||||||
if (i != 0 && i != INFINITE)
|
|
||||||
{
|
|
||||||
// ICMP response received
|
|
||||||
INTERRUPT_MANAGER *interrupt = NewInterruptManager();
|
|
||||||
UINT64 giveup_time = Tick64() + (UINT64)timeout;
|
|
||||||
UINT recv_buffer_size = (sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + size + 64) * 2;
|
|
||||||
UCHAR *recv_buffer = Malloc(recv_buffer_size);
|
|
||||||
|
|
||||||
AddInterrupt(interrupt, giveup_time);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
UINT interval = GetNextIntervalForInterrupt(interrupt);
|
|
||||||
IP src_ip;
|
|
||||||
UINT src_port;
|
|
||||||
SOCKSET set;
|
|
||||||
|
|
||||||
InitSockSet(&set);
|
|
||||||
AddSockSet(&set, s);
|
|
||||||
|
|
||||||
Select(&set, interval, NULL, NULL);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
Zero(recv_buffer, recv_buffer_size);
|
|
||||||
i = RecvFrom(s, &src_ip, &src_port, recv_buffer, recv_buffer_size);
|
|
||||||
recv_tick = TickHighres64();
|
|
||||||
|
|
||||||
if (i != 0 && i != SOCK_LATER)
|
|
||||||
{
|
|
||||||
ret = IcmpParseResult(dest_ip, id, seq, recv_buffer, i);
|
|
||||||
|
|
||||||
if (ret != NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interval == 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeInterruptManager(interrupt);
|
|
||||||
|
|
||||||
Free(recv_buffer);
|
|
||||||
|
|
||||||
if (ret == NULL)
|
|
||||||
{
|
|
||||||
ret = ZeroMalloc(sizeof(ICMP_RESULT));
|
|
||||||
|
|
||||||
ret->Timeout = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Free(send_buffer);
|
|
||||||
ReleaseSock(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get whether the packet is a DHCP packet associated with the specified MAC address
|
// Get whether the packet is a DHCP packet associated with the specified MAC address
|
||||||
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address)
|
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address)
|
||||||
{
|
{
|
||||||
@ -575,7 +419,6 @@ UINT GetIpHeaderSize(UCHAR *src, UINT src_size)
|
|||||||
{
|
{
|
||||||
UCHAR ip_ver;
|
UCHAR ip_ver;
|
||||||
TCP_HEADER *tcp = NULL;
|
TCP_HEADER *tcp = NULL;
|
||||||
UINT tcp_size = 0;
|
|
||||||
IPV4_HEADER *ip = NULL;
|
IPV4_HEADER *ip = NULL;
|
||||||
IPV6_HEADER *ip6 = NULL;
|
IPV6_HEADER *ip6 = NULL;
|
||||||
// Validate arguments
|
// Validate arguments
|
||||||
@ -1031,7 +874,6 @@ void VLanInsertTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vla
|
|||||||
// Remove the VLAN tag from the packet
|
// Remove the VLAN tag from the packet
|
||||||
bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vlan_tpid)
|
bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vlan_tpid)
|
||||||
{
|
{
|
||||||
bool has_vlan_tag = false;
|
|
||||||
UCHAR *src_data;
|
UCHAR *src_data;
|
||||||
UINT src_size;
|
UINT src_size;
|
||||||
USHORT vlan_tpid_ushort;
|
USHORT vlan_tpid_ushort;
|
||||||
@ -1993,7 +1835,6 @@ void CorrectChecksum(PKT *p)
|
|||||||
|
|
||||||
if (tcp != NULL)
|
if (tcp != NULL)
|
||||||
{
|
{
|
||||||
UINT tcp_header_size = TCP_GET_HEADER_SIZE(tcp) * 4;
|
|
||||||
USHORT tcp_offloading_checksum1 = CalcChecksumForIPv6(&v6->SrcAddress, &v6->DestAddress, IP_PROTO_TCP, NULL, 0, v6info->PayloadSize);
|
USHORT tcp_offloading_checksum1 = CalcChecksumForIPv6(&v6->SrcAddress, &v6->DestAddress, IP_PROTO_TCP, NULL, 0, v6info->PayloadSize);
|
||||||
USHORT tcp_offloading_checksum2 = ~tcp_offloading_checksum1;
|
USHORT tcp_offloading_checksum2 = ~tcp_offloading_checksum1;
|
||||||
|
|
||||||
@ -2191,10 +2032,6 @@ HTTPLOG *ParseHttpAccessLog(PKT *pkt)
|
|||||||
|
|
||||||
|
|
||||||
// Layer-2 parsing
|
// Layer-2 parsing
|
||||||
bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size)
|
|
||||||
{
|
|
||||||
return ParsePacketL2Ex(p, buf, size, false);
|
|
||||||
}
|
|
||||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||||
{
|
{
|
||||||
UINT i;
|
UINT i;
|
||||||
@ -4062,11 +3899,6 @@ void DhcpParseClasslessRouteData(DHCP_CLASSLESS_ROUTE_TABLE *t, void *data, UINT
|
|||||||
}
|
}
|
||||||
|
|
||||||
data_len = (subnet_mask_len + 7) / 8;
|
data_len = (subnet_mask_len + 7) / 8;
|
||||||
if (data_len > 4)
|
|
||||||
{
|
|
||||||
// Invalid data
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Zero(tmp, sizeof(tmp));
|
Zero(tmp, sizeof(tmp));
|
||||||
if (ReadBuf(b, tmp, data_len) != data_len)
|
if (ReadBuf(b, tmp, data_len) != data_len)
|
||||||
|
@ -860,7 +860,6 @@ void FreePacketUDPv4(PKT *p);
|
|||||||
void FreePacketTCPv4(PKT *p);
|
void FreePacketTCPv4(PKT *p);
|
||||||
void FreePacketICMPv4(PKT *p);
|
void FreePacketICMPv4(PKT *p);
|
||||||
void FreePacketDHCPv4(PKT *p);
|
void FreePacketDHCPv4(PKT *p);
|
||||||
bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size);
|
|
||||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3);
|
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3);
|
||||||
bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size);
|
bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size);
|
||||||
bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size);
|
bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size);
|
||||||
@ -909,8 +908,6 @@ UCHAR GetNextByte(BUF *b);
|
|||||||
|
|
||||||
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address);
|
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address);
|
||||||
|
|
||||||
ICMP_RESULT *IcmpEchoSendBySocket(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout);
|
|
||||||
ICMP_RESULT *IcmpEchoSend(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout);
|
|
||||||
ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR *recv_buffer, UINT recv_buffer_size);
|
ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR *recv_buffer, UINT recv_buffer_size);
|
||||||
void IcmpFreeResult(ICMP_RESULT *r);
|
void IcmpFreeResult(ICMP_RESULT *r);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user