mirror of
https://github.com/ValdikSS/GoodbyeDPI.git
synced 2024-12-22 06:15:27 +00:00
Fix all the warnings and notes
This commit is contained in:
parent
a79377f606
commit
ed42c5d627
@ -14,7 +14,7 @@ CC = $(CPREFIX)gcc
|
||||
CCWINDRES = $(CPREFIX)windres
|
||||
CFLAGS = -std=c99 -pie -fPIE -pipe -I$(WINDIVERTHEADERS) -L$(WINDIVERTLIBS) \
|
||||
-O2 -D_FORTIFY_SOURCE=2 -fstack-protector \
|
||||
-Wall -Wextra -Wpedantic -Wformat=2 -Wshadow -Wstrict-aliasing=1 -Werror=format-security \
|
||||
-Wall -Wextra -Wpedantic -Wformat=2 -Wno-format-nonliteral -Wshadow -Wstrict-aliasing=1 -Werror=format-security \
|
||||
-Wfloat-equal -Wcast-align -Wsign-conversion \
|
||||
#-fstack-protector-strong
|
||||
LDFLAGS = -fstack-protector -Wl,-O1,-pie,--dynamicbase,--nxcompat,--sort-common,--as-needed \
|
||||
|
@ -35,14 +35,11 @@ static int add_hostname(const char *host) {
|
||||
if (!host)
|
||||
return FALSE;
|
||||
|
||||
int host_len = strlen(host);
|
||||
|
||||
blackwhitelist_record_t *tmp_record = malloc(sizeof(blackwhitelist_record_t));
|
||||
char *host_c = malloc(host_len + 1);
|
||||
char *host_c = NULL;
|
||||
|
||||
if (!check_get_hostname(host)) {
|
||||
strncpy(host_c, host, host_len);
|
||||
host_c[host_len] = '\0';
|
||||
host_c = strdup(host);
|
||||
tmp_record->host = host_c;
|
||||
HASH_ADD_KEYPTR(hh, blackwhitelist, tmp_record->host,
|
||||
strlen(tmp_record->host), tmp_record);
|
||||
@ -51,7 +48,8 @@ static int add_hostname(const char *host) {
|
||||
}
|
||||
debug("Not added host %s\n", host);
|
||||
free(tmp_record);
|
||||
free(host_c);
|
||||
if (host_c)
|
||||
free(host_c);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ static time_t last_cleanup = 0;
|
||||
static udp_connrecord_t *conntrack = NULL;
|
||||
|
||||
void flush_dns_cache() {
|
||||
BOOL WINAPI (*DnsFlushResolverCache)();
|
||||
long long int WINAPI (*DnsFlushResolverCache)();
|
||||
|
||||
HMODULE dnsapi = LoadLibrary("dnsapi.dll");
|
||||
if (dnsapi == NULL)
|
||||
@ -53,7 +53,7 @@ void flush_dns_cache() {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
DnsFlushResolverCache = (void*)GetProcAddress(dnsapi, "DnsFlushResolverCache");
|
||||
DnsFlushResolverCache = GetProcAddress(dnsapi, "DnsFlushResolverCache");
|
||||
if (DnsFlushResolverCache == NULL || !DnsFlushResolverCache())
|
||||
printf("Can't flush DNS cache!");
|
||||
FreeLibrary(dnsapi);
|
||||
|
@ -7,9 +7,9 @@
|
||||
#include "windivert.h"
|
||||
#include "goodbyedpi.h"
|
||||
|
||||
static const char fake_http_request[] = "GET / HTTP/1.1\r\nHost: www.w3.org\r\n"
|
||||
"User-Agent: curl/7.65.3\r\nAccept: */*\r\n"
|
||||
"Accept-Encoding: deflate, gzip, br\r\n\r\n";
|
||||
static const unsigned char fake_http_request[] = "GET / HTTP/1.1\r\nHost: www.w3.org\r\n"
|
||||
"User-Agent: curl/7.65.3\r\nAccept: */*\r\n"
|
||||
"Accept-Encoding: deflate, gzip, br\r\n\r\n";
|
||||
static const unsigned char fake_https_request[] = {
|
||||
0x16, 0x03, 0x01, 0x02, 0x00, 0x01, 0x00, 0x01, 0xfc, 0x03, 0x03, 0x9a, 0x8f, 0xa7, 0x6a, 0x5d,
|
||||
0x57, 0xf3, 0x62, 0x19, 0xbe, 0x46, 0x82, 0x45, 0xe2, 0x59, 0x5c, 0xb4, 0x48, 0x31, 0x12, 0x15,
|
||||
@ -64,7 +64,7 @@ static int send_fake_data(const HANDLE w_filter,
|
||||
PWINDIVERT_IPHDR ppIpHdr;
|
||||
PWINDIVERT_IPV6HDR ppIpV6Hdr;
|
||||
PWINDIVERT_TCPHDR ppTcpHdr;
|
||||
char *fake_request_data = is_https ? fake_https_request : fake_http_request;
|
||||
unsigned const char *fake_request_data = is_https ? fake_https_request : fake_http_request;
|
||||
UINT fake_request_size = is_https ? sizeof(fake_https_request) : sizeof(fake_http_request) - 1;
|
||||
|
||||
memcpy(&addr_new, addr, sizeof(WINDIVERT_ADDRESS));
|
||||
@ -120,7 +120,7 @@ static int send_fake_data(const HANDLE w_filter,
|
||||
}
|
||||
|
||||
// Recalculate the checksum
|
||||
WinDivertHelperCalcChecksums(packet_fake, packetLen_new, &addr_new, NULL);
|
||||
WinDivertHelperCalcChecksums(packet_fake, packetLen_new, &addr_new, (UINT64)NULL);
|
||||
|
||||
if (set_checksum) {
|
||||
// ...and damage it
|
||||
|
@ -165,9 +165,9 @@ static void add_filter_str(int proto, int port) {
|
||||
|
||||
strcpy(new_filter, current_filter);
|
||||
if (proto == IPPROTO_UDP)
|
||||
sprintf(&(new_filter[strlen(new_filter)]), udp, port, port);
|
||||
sprintf(new_filter + strlen(new_filter), udp, port, port);
|
||||
else
|
||||
sprintf(&(new_filter[strlen(new_filter)]), tcp, port, port);
|
||||
sprintf(new_filter + strlen(new_filter), tcp, port, port);
|
||||
|
||||
filter_string = new_filter;
|
||||
free(current_filter);
|
||||
@ -327,18 +327,18 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen,
|
||||
hdr_begin = dumb_memmem(pktdata, pktlen,
|
||||
hdrname, strlen(hdrname));
|
||||
if (!hdr_begin) return FALSE;
|
||||
if ((PVOID)pktdata > (PVOID)hdr_begin) return FALSE;
|
||||
if (pktdata > hdr_begin) return FALSE;
|
||||
|
||||
/* Set header address */
|
||||
*hdrnameaddr = hdr_begin;
|
||||
*hdrvalueaddr = (PVOID)hdr_begin + strlen(hdrname);
|
||||
*hdrvalueaddr = hdr_begin + strlen(hdrname);
|
||||
|
||||
/* Search for header end (\r\n) */
|
||||
data_addr_rn = dumb_memmem(*hdrvalueaddr,
|
||||
pktlen - ((PVOID)*hdrvalueaddr - (PVOID)pktdata),
|
||||
pktlen - (*hdrvalueaddr - pktdata),
|
||||
"\r\n", 2);
|
||||
if (data_addr_rn) {
|
||||
*hdrvaluelen = (PVOID)data_addr_rn - (PVOID)*hdrvalueaddr;
|
||||
*hdrvaluelen = data_addr_rn - *hdrvalueaddr;
|
||||
if (*hdrvaluelen > 0u && *hdrvaluelen <= 512u)
|
||||
return TRUE;
|
||||
}
|
||||
@ -351,8 +351,8 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen,
|
||||
static int extract_sni(const char *pktdata, unsigned int pktlen,
|
||||
char **hostnameaddr, unsigned int *hostnamelen) {
|
||||
uint32_t ptr = 0;
|
||||
const char *d = pktdata;
|
||||
const char *hnaddr = 0;
|
||||
unsigned char *d = (unsigned char*)pktdata;
|
||||
unsigned char *hnaddr = 0;
|
||||
unsigned int hnlen = 0;
|
||||
|
||||
while (ptr + 8 < pktlen) {
|
||||
@ -374,15 +374,15 @@ static int extract_sni(const char *pktdata, unsigned int pktlen,
|
||||
return FALSE;
|
||||
}
|
||||
/* Validate that hostname has only ascii lowercase characters */
|
||||
for (int i=0; i<hnlen; i++) {
|
||||
if (!(hnaddr[i] >= '1' && hnaddr[i] <= '9' ||
|
||||
hnaddr[i] >= 'a' && hnaddr[i] <= 'z' ||
|
||||
hnaddr[i] == '.'))
|
||||
for (unsigned int i=0; i<hnlen; i++) {
|
||||
if (!( (hnaddr[i] >= '1' && hnaddr[i] <= '9') ||
|
||||
(hnaddr[i] >= 'a' && hnaddr[i] <= 'z') ||
|
||||
hnaddr[i] == '.'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
*hostnameaddr = hnaddr;
|
||||
*hostnameaddr = (char*)hnaddr;
|
||||
*hostnamelen = hnlen;
|
||||
return TRUE;
|
||||
}
|
||||
@ -425,12 +425,12 @@ static PVOID find_http_method_end(const char *pkt, unsigned int http_frag, int *
|
||||
* This function cuts off the end of the packet (step=0) or
|
||||
* the beginning of the packet (step=1) with fragment_size bytes.
|
||||
*/
|
||||
static PVOID send_native_fragment(HANDLE w_filter, WINDIVERT_ADDRESS addr,
|
||||
static void send_native_fragment(HANDLE w_filter, WINDIVERT_ADDRESS addr,
|
||||
char *packet, UINT packetLen, PVOID packet_data,
|
||||
UINT packet_dataLen, int packet_v4, int packet_v6,
|
||||
PWINDIVERT_IPHDR ppIpHdr, PWINDIVERT_IPV6HDR ppIpV6Hdr,
|
||||
PWINDIVERT_TCPHDR ppTcpHdr,
|
||||
int fragment_size, int step) {
|
||||
unsigned int fragment_size, int step) {
|
||||
char packet_bak[MAX_PACKET_SIZE];
|
||||
memcpy(&packet_bak, packet, packetLen);
|
||||
UINT orig_packetLen = packetLen;
|
||||
@ -464,7 +464,7 @@ static PVOID send_native_fragment(HANDLE w_filter, WINDIVERT_ADDRESS addr,
|
||||
//printf("step1 (%d:%d), pp:%d, was:%d, now:%d\n", packet_v4, packet_v6, ntohs(ppIpHdr->Length),
|
||||
// packetLen, packetLen - fragment_size);
|
||||
memmove(packet_data,
|
||||
packet_data + fragment_size,
|
||||
(char*)packet_data + fragment_size,
|
||||
packet_dataLen - fragment_size);
|
||||
packetLen -= fragment_size;
|
||||
|
||||
@ -1059,7 +1059,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (method_addr) {
|
||||
memmove(method_addr + 1, method_addr,
|
||||
(PVOID)host_addr - (PVOID)method_addr - 1);
|
||||
(size_t)(host_addr - method_addr - 1));
|
||||
should_recalc_checksum = 1;
|
||||
}
|
||||
}
|
||||
@ -1087,10 +1087,10 @@ int main(int argc, char *argv[]) {
|
||||
* to the end of User-Agent
|
||||
*/
|
||||
memmove(host_addr - 1, host_addr,
|
||||
(PVOID)useragent_addr + useragent_len - (PVOID)host_addr);
|
||||
(size_t)(useragent_addr + useragent_len - host_addr));
|
||||
host_addr -= 1;
|
||||
/* Put space in the end of User-Agent header */
|
||||
*(char*)((PVOID)useragent_addr + useragent_len - 1) = ' ';
|
||||
*(char*)((uint8_t*)useragent_addr + useragent_len - 1) = ' ';
|
||||
should_recalc_checksum = 1;
|
||||
//printf("Replaced Host header!\n");
|
||||
}
|
||||
@ -1100,11 +1100,11 @@ int main(int argc, char *argv[]) {
|
||||
/* Move one byte to the RIGHT from the end of User-Agent
|
||||
* to the "Host:"
|
||||
*/
|
||||
memmove((PVOID)useragent_addr + useragent_len + 1,
|
||||
(PVOID)useragent_addr + useragent_len,
|
||||
(PVOID)host_addr - 1 - ((PVOID)useragent_addr + useragent_len));
|
||||
memmove(useragent_addr + useragent_len + 1,
|
||||
useragent_addr + useragent_len,
|
||||
(size_t)(host_addr - 1 - (useragent_addr + useragent_len)));
|
||||
/* Put space in the end of User-Agent header */
|
||||
*(char*)((PVOID)useragent_addr + useragent_len) = ' ';
|
||||
*(char*)((uint8_t*)useragent_addr + useragent_len) = ' ';
|
||||
should_recalc_checksum = 1;
|
||||
//printf("Replaced Host header!\n");
|
||||
}
|
||||
@ -1160,7 +1160,8 @@ int main(int argc, char *argv[]) {
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort,
|
||||
0, ppIpHdr->TTL))
|
||||
||
|
||||
(packet_v6 && tcp_handle_incoming(&ppIpV6Hdr->SrcAddr, &ppIpV6Hdr->DstAddr,
|
||||
(packet_v6 && tcp_handle_incoming((uint32_t*)&ppIpV6Hdr->SrcAddr,
|
||||
(uint32_t*)&ppIpV6Hdr->DstAddr,
|
||||
ppTcpHdr->SrcPort, ppTcpHdr->DstPort,
|
||||
1, ppIpV6Hdr->HopLimit))))
|
||||
{
|
||||
@ -1252,7 +1253,7 @@ int main(int argc, char *argv[]) {
|
||||
if (should_reinject) {
|
||||
//printf("Re-injecting!\n");
|
||||
if (should_recalc_checksum) {
|
||||
WinDivertHelperCalcChecksums(packet, packetLen, &addr, NULL);
|
||||
WinDivertHelperCalcChecksums(packet, packetLen, &addr, (UINT64)NULL);
|
||||
}
|
||||
WinDivertSend(w_filter, packet, packetLen, &addr, NULL);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ int service_register(int argc, char *argv[])
|
||||
*/
|
||||
if (!service_argc && !service_argv) {
|
||||
service_argc = argc;
|
||||
service_argv = malloc(sizeof(void*) * argc);
|
||||
service_argv = malloc(sizeof(void*) * (size_t)argc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
service_argv[i] = strdup(argv[i]);
|
||||
}
|
||||
@ -71,7 +71,7 @@ void service_main(int argc __attribute__((unused)),
|
||||
SetServiceStatus(hStatus, &ServiceStatus);
|
||||
|
||||
// Calling main with saved argc & argv
|
||||
ServiceStatus.dwWin32ExitCode = main(service_argc, service_argv);
|
||||
ServiceStatus.dwWin32ExitCode = (DWORD)main(service_argc, service_argv);
|
||||
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
SetServiceStatus(hStatus, &ServiceStatus);
|
||||
return;
|
||||
|
@ -41,7 +41,7 @@ static tcp_connrecord_t *conntrack = NULL;
|
||||
inline static void fill_key_data(char *key, const uint8_t is_ipv6, const uint32_t srcip[4],
|
||||
const uint32_t dstip[4], const uint16_t srcport, const uint16_t dstport)
|
||||
{
|
||||
int offset = 0;
|
||||
unsigned int offset = 0;
|
||||
|
||||
if (is_ipv6) {
|
||||
*(uint8_t*)(key) = '6';
|
||||
@ -69,7 +69,7 @@ inline static void fill_key_data(char *key, const uint8_t is_ipv6, const uint32_
|
||||
inline static void fill_data_from_key(uint8_t *is_ipv6, uint32_t srcip[4], uint32_t dstip[4],
|
||||
uint16_t *srcport, uint16_t *dstport, const char *key)
|
||||
{
|
||||
int offset = 0;
|
||||
unsigned int offset = 0;
|
||||
|
||||
if (key[0] == '6') {
|
||||
*is_ipv6 = 1;
|
||||
@ -179,9 +179,9 @@ static void tcp_cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
int tcp_handle_incoming(const uint32_t srcip[4], const uint32_t dstip[4],
|
||||
const uint16_t srcport, const uint16_t dstport,
|
||||
const uint8_t is_ipv6, const uint8_t ttl)
|
||||
int tcp_handle_incoming(uint32_t srcip[4], uint32_t dstip[4],
|
||||
uint16_t srcport, uint16_t dstport,
|
||||
uint8_t is_ipv6, uint8_t ttl)
|
||||
{
|
||||
tcp_cleanup();
|
||||
|
||||
@ -192,10 +192,10 @@ int tcp_handle_incoming(const uint32_t srcip[4], const uint32_t dstip[4],
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int tcp_handle_outgoing(const uint32_t srcip[4], const uint32_t dstip[4],
|
||||
const uint16_t srcport, const uint16_t dstport,
|
||||
int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4],
|
||||
uint16_t srcport, uint16_t dstport,
|
||||
tcp_conntrack_info_t *conn_info,
|
||||
const uint8_t is_ipv6)
|
||||
uint8_t is_ipv6)
|
||||
{
|
||||
char key[TCP_CONNRECORD_KEY_LEN];
|
||||
tcp_connrecord_t *tmp_connrecord = NULL;
|
||||
|
@ -12,14 +12,14 @@ typedef struct tcp_conntrack_info {
|
||||
uint16_t dstport;
|
||||
} tcp_conntrack_info_t;
|
||||
|
||||
int tcp_handle_incoming(const uint32_t srcip[4], const uint32_t dstip[4],
|
||||
const uint16_t srcport, const uint16_t dstport,
|
||||
const uint8_t is_ipv6, const uint8_t ttl);
|
||||
int tcp_handle_incoming(uint32_t srcip[4], uint32_t dstip[4],
|
||||
uint16_t srcport, uint16_t dstport,
|
||||
uint8_t is_ipv6, uint8_t ttl);
|
||||
|
||||
int tcp_handle_outgoing(const uint32_t srcip[4], const uint32_t dstip[4],
|
||||
const uint16_t srcport, const uint16_t dstport,
|
||||
int tcp_handle_outgoing(uint32_t srcip[4], uint32_t dstip[4],
|
||||
uint16_t srcport, uint16_t dstport,
|
||||
tcp_conntrack_info_t *conn_info,
|
||||
const uint8_t is_ipv6);
|
||||
uint8_t is_ipv6);
|
||||
|
||||
int tcp_get_auto_ttl(const uint8_t ttl, const uint8_t decrease_for);
|
||||
int tcp_get_auto_ttl(uint8_t ttl, uint8_t decrease_for);
|
||||
#endif
|
||||
|
@ -46,11 +46,11 @@ char *repl_str(const char *str, const char *from, const char *to) {
|
||||
}
|
||||
}
|
||||
|
||||
pos_cache[count-1] = pstr2 - str;
|
||||
pos_cache[count-1] = (uintptr_t)(pstr2 - str);
|
||||
pstr = pstr2 + fromlen;
|
||||
}
|
||||
|
||||
orglen = pstr - str + strlen(pstr);
|
||||
orglen = (size_t)(pstr - str) + strlen(pstr);
|
||||
|
||||
/* Allocate memory for the post-replacement string. */
|
||||
if (count > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user