From 8ca0ce3efc53e2f159d4acf17bd6baa0672083ee Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sat, 18 Aug 2018 00:27:17 +0500 Subject: [PATCH 1/2] src/Mayaqua/TcpIp: remove dead code, unused variables and fuctions found by coverity, cppcheck [src/Mayaqua/TcpIp.c:578]: (style) Variable 'tcp_size' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:1034]: (style) Variable 'has_vlan_tag' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:1996]: (style) Variable 'tcp_header_size' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:127]: (style) The function 'IcmpEchoSend' is never used. [src/Mayaqua/TcpIp.c:2194]: (style) The function 'ParsePacketL2' is never used. [src/Mayaqua/TcpIp.c:251]: (style) The function 'IcmpEchoSendBySocket' is never used. --- src/Mayaqua/TcpIp.c | 168 -------------------------------------------- src/Mayaqua/TcpIp.h | 3 - 2 files changed, 171 deletions(-) diff --git a/src/Mayaqua/TcpIp.c b/src/Mayaqua/TcpIp.c index 8d48a44c..5b3dfbf0 100644 --- a/src/Mayaqua/TcpIp.c +++ b/src/Mayaqua/TcpIp.c @@ -122,30 +122,6 @@ #include #include - -// 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 void IcmpFreeResult(ICMP_RESULT *r) { @@ -271,138 +247,6 @@ ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR 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 bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address) { @@ -575,7 +419,6 @@ UINT GetIpHeaderSize(UCHAR *src, UINT src_size) { UCHAR ip_ver; TCP_HEADER *tcp = NULL; - UINT tcp_size = 0; IPV4_HEADER *ip = NULL; IPV6_HEADER *ip6 = NULL; // 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 bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vlan_tpid) { - bool has_vlan_tag = false; UCHAR *src_data; UINT src_size; USHORT vlan_tpid_ushort; @@ -1993,7 +1835,6 @@ void CorrectChecksum(PKT *p) 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_checksum2 = ~tcp_offloading_checksum1; @@ -2191,10 +2032,6 @@ HTTPLOG *ParseHttpAccessLog(PKT *pkt) // 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) { UINT i; @@ -4062,11 +3899,6 @@ void DhcpParseClasslessRouteData(DHCP_CLASSLESS_ROUTE_TABLE *t, void *data, UINT } data_len = (subnet_mask_len + 7) / 8; - if (data_len > 4) - { - // Invalid data - break; - } Zero(tmp, sizeof(tmp)); if (ReadBuf(b, tmp, data_len) != data_len) diff --git a/src/Mayaqua/TcpIp.h b/src/Mayaqua/TcpIp.h index e35238a8..27c11965 100644 --- a/src/Mayaqua/TcpIp.h +++ b/src/Mayaqua/TcpIp.h @@ -860,7 +860,6 @@ void FreePacketUDPv4(PKT *p); void FreePacketTCPv4(PKT *p); void FreePacketICMPv4(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 ParsePacketARPv4(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); -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); void IcmpFreeResult(ICMP_RESULT *r); From e460f26b1994d9eafa0ffdb33730f72c35d3f02c Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sat, 18 Aug 2018 00:34:42 +0500 Subject: [PATCH 2/2] src/Cedar/IPsec_PPP: remove dead code, unused fuction found by coverity, cppcheck [src/Cedar/IPsec_PPP.c:2655]: (style) The function 'MsChapV2Client_GenerateChallenge' is never used. --- src/Cedar/IPsec_PPP.c | 16 ---------------- src/Cedar/IPsec_PPP.h | 1 - 2 files changed, 17 deletions(-) diff --git a/src/Cedar/IPsec_PPP.c b/src/Cedar/IPsec_PPP.c index 6721172a..eebda7eb 100644 --- a/src/Cedar/IPsec_PPP.c +++ b/src/Cedar/IPsec_PPP.c @@ -2312,10 +2312,6 @@ PPP_LCP *ParseLCP(USHORT protocol, void *data, UINT size) c->OptionList = NewListFast(NULL); // Code - if (size < 1) - { - goto LABEL_ERROR; - } c->Code = buf[0]; buf++; size--; @@ -2655,18 +2651,6 @@ void MsChapV2Server_GenerateChallenge(UCHAR *dst) 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 void MsChapV2_GenerateChallenge8(UCHAR *dst, UCHAR *client_challenge, UCHAR *server_challenge, char *username) { diff --git a/src/Cedar/IPsec_PPP.h b/src/Cedar/IPsec_PPP.h index 58f94519..66571313 100644 --- a/src/Cedar/IPsec_PPP.h +++ b/src/Cedar/IPsec_PPP.h @@ -329,7 +329,6 @@ bool IsHubExistsWithLock(CEDAR *cedar, char *hubname); void GenerateNtPasswordHash(UCHAR *dst, char *password); void GenerateNtPasswordHashHash(UCHAR *dst_hash, UCHAR *src_hash); void MsChapV2Server_GenerateChallenge(UCHAR *dst); -void MsChapV2Client_GenerateChallenge(UCHAR *dst); 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 MsChapV2Server_GenerateResponse(UCHAR *dst, UCHAR *nt_password_hash_hash, UCHAR *client_response, UCHAR *challenge8);