Fix all types and warnings

This commit is contained in:
ValdikSS 2021-12-27 16:04:41 +03:00
parent 46219e95e7
commit 67c226dc7c
4 changed files with 25 additions and 23 deletions

View File

@ -70,8 +70,10 @@ int blackwhitelist_load_list(const char *filename) {
line); line);
continue; continue;
} }
if (strlen(line) < 4) if (strlen(line) < 3) {
printf("WARNING: host %s is less than 3 bytes, skipping\n", line);
continue; continue;
}
if (add_hostname(line)) if (add_hostname(line))
cnt++; cnt++;
} }

View File

@ -44,7 +44,7 @@ static time_t last_cleanup = 0;
static udp_connrecord_t *conntrack = NULL; static udp_connrecord_t *conntrack = NULL;
void flush_dns_cache() { void flush_dns_cache() {
long long int WINAPI (*DnsFlushResolverCache)(); INT_PTR WINAPI (*DnsFlushResolverCache)();
HMODULE dnsapi = LoadLibrary("dnsapi.dll"); HMODULE dnsapi = LoadLibrary("dnsapi.dll");
if (dnsapi == NULL) if (dnsapi == NULL)

View File

@ -120,7 +120,7 @@ static int send_fake_data(const HANDLE w_filter,
} }
// Recalculate the checksum // Recalculate the checksum
WinDivertHelperCalcChecksums(packet_fake, packetLen_new, &addr_new, (UINT64)NULL); WinDivertHelperCalcChecksums(packet_fake, packetLen_new, &addr_new, 0ULL);
if (set_checksum) { if (set_checksum) {
// ...and damage it // ...and damage it

View File

@ -89,7 +89,7 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA
} \ } \
else if (http_fragment_size != (unsigned int)fragment_size) { \ else if (http_fragment_size != (unsigned int)fragment_size) { \
printf( \ printf( \
"WARNING: HTTP fragment size is already set to %d, not changing.\n", \ "WARNING: HTTP fragment size is already set to %u, not changing.\n", \
http_fragment_size \ http_fragment_size \
); \ ); \
} \ } \
@ -203,7 +203,7 @@ static void finalize_filter_strings() {
} }
static char* dumb_memmem(const char* haystack, unsigned int hlen, static char* dumb_memmem(const char* haystack, unsigned int hlen,
const char* needle, size_t nlen) const char* needle, unsigned int nlen)
{ {
// naive implementation // naive implementation
if (nlen > hlen) return NULL; if (nlen > hlen) return NULL;
@ -337,11 +337,11 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen,
/* Search for header end (\r\n) */ /* Search for header end (\r\n) */
data_addr_rn = dumb_memmem(*hdrvalueaddr, data_addr_rn = dumb_memmem(*hdrvalueaddr,
pktlen - (*hdrvalueaddr - pktdata), pktlen - (uintptr_t)(*hdrvalueaddr - pktdata),
"\r\n", 2); "\r\n", 2);
if (data_addr_rn) { if (data_addr_rn) {
*hdrvaluelen = data_addr_rn - *hdrvalueaddr; *hdrvaluelen = (uintptr_t)(data_addr_rn - *hdrvalueaddr);
if (*hdrvaluelen > 0u && *hdrvaluelen <= 512u) if (*hdrvaluelen >= 3 && *hdrvaluelen <= HOST_MAXLEN)
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -352,10 +352,10 @@ static int find_header_and_get_info(const char *pktdata, unsigned int pktlen,
*/ */
static int extract_sni(const char *pktdata, unsigned int pktlen, static int extract_sni(const char *pktdata, unsigned int pktlen,
char **hostnameaddr, unsigned int *hostnamelen) { char **hostnameaddr, unsigned int *hostnamelen) {
uint32_t ptr = 0; unsigned int ptr = 0;
unsigned char *d = (unsigned char*)pktdata; unsigned const char *d = (unsigned const char *)pktdata;
unsigned char *hnaddr = 0; unsigned const char *hnaddr = 0;
unsigned int hnlen = 0; int hnlen = 0;
while (ptr + 8 < pktlen) { while (ptr + 8 < pktlen) {
/* Search for specific Extensions sequence */ /* Search for specific Extensions sequence */
@ -371,12 +371,12 @@ static int extract_sni(const char *pktdata, unsigned int pktlen,
} }
hnaddr = &d[ptr+9]; hnaddr = &d[ptr+9];
hnlen = d[ptr+8]; hnlen = d[ptr+8];
/* Limit hostname size up to 254 bytes */ /* Limit hostname size up to 253 bytes */
if (hnlen < 2 || hnlen > 254) { if (hnlen < 3 || hnlen > HOST_MAXLEN) {
return FALSE; return FALSE;
} }
/* Validate that hostname has only ascii lowercase characters */ /* Validate that hostname has only ascii lowercase characters */
for (unsigned int i=0; i<hnlen; i++) { for (int i=0; i<hnlen; i++) {
if (!( (hnaddr[i] >= '1' && hnaddr[i] <= '9') || if (!( (hnaddr[i] >= '1' && hnaddr[i] <= '9') ||
(hnaddr[i] >= 'a' && hnaddr[i] <= 'z') || (hnaddr[i] >= 'a' && hnaddr[i] <= 'z') ||
hnaddr[i] == '.')) hnaddr[i] == '.'))
@ -385,7 +385,7 @@ static int extract_sni(const char *pktdata, unsigned int pktlen,
} }
} }
*hostnameaddr = (char*)hnaddr; *hostnameaddr = (char*)hnaddr;
*hostnamelen = hnlen; *hostnamelen = (unsigned int)hnlen;
return TRUE; return TRUE;
} }
ptr++; ptr++;
@ -833,8 +833,8 @@ int main(int argc, char *argv[]) {
if (!https_fragment_size) if (!https_fragment_size)
https_fragment_size = 2; https_fragment_size = 2;
printf("Block passive: %d\nFragment HTTP: %d\nFragment persistent HTTP: %d\n" printf("Block passive: %d\nFragment HTTP: %u\nFragment persistent HTTP: %u\n"
"Fragment HTTPS: %d\nNative fragmentation (splitting): %d\n" "Fragment HTTPS: %u\nNative fragmentation (splitting): %d\n"
"Fragments sending in reverse: %d\n" "Fragments sending in reverse: %d\n"
"hoSt: %d\nHost no space: %d\nAdditional space: %d\n" "hoSt: %d\nHost no space: %d\nAdditional space: %d\n"
"Mix Host: %d\nHTTP AllPorts: %d\nHTTP Persistent Nowait: %d\n" "Mix Host: %d\nHTTP AllPorts: %d\nHTTP Persistent Nowait: %d\n"
@ -980,7 +980,7 @@ int main(int argc, char *argv[]) {
: 1) : 1)
{ {
#ifdef DEBUG #ifdef DEBUG
unsigned char lsni[256] = {0}; char lsni[HOST_MAXLEN + 1] = {0};
extract_sni(packet_data, packet_dataLen, extract_sni(packet_data, packet_dataLen,
&host_addr, &host_len); &host_addr, &host_len);
memcpy(&lsni, host_addr, host_len); memcpy(&lsni, host_addr, host_len);
@ -1021,7 +1021,7 @@ int main(int argc, char *argv[]) {
host_addr = hdr_value_addr; host_addr = hdr_value_addr;
host_len = hdr_value_len; host_len = hdr_value_len;
#ifdef DEBUG #ifdef DEBUG
unsigned char lhost[256] = {0}; char lhost[HOST_MAXLEN + 1] = {0};
memcpy(&lhost, host_addr, host_len); memcpy(&lhost, host_addr, host_len);
printf("Blocked HTTP website Host: %s\n", lhost); printf("Blocked HTTP website Host: %s\n", lhost);
#endif #endif
@ -1092,7 +1092,7 @@ int main(int argc, char *argv[]) {
(size_t)(useragent_addr + useragent_len - host_addr)); (size_t)(useragent_addr + useragent_len - host_addr));
host_addr -= 1; host_addr -= 1;
/* Put space in the end of User-Agent header */ /* Put space in the end of User-Agent header */
*(char*)((uint8_t*)useragent_addr + useragent_len - 1) = ' '; *(char*)((unsigned char*)useragent_addr + useragent_len - 1) = ' ';
should_recalc_checksum = 1; should_recalc_checksum = 1;
//printf("Replaced Host header!\n"); //printf("Replaced Host header!\n");
} }
@ -1106,7 +1106,7 @@ int main(int argc, char *argv[]) {
useragent_addr + useragent_len, useragent_addr + useragent_len,
(size_t)(host_addr - 1 - (useragent_addr + useragent_len))); (size_t)(host_addr - 1 - (useragent_addr + useragent_len)));
/* Put space in the end of User-Agent header */ /* Put space in the end of User-Agent header */
*(char*)((uint8_t*)useragent_addr + useragent_len) = ' '; *(char*)((unsigned char*)useragent_addr + useragent_len) = ' ';
should_recalc_checksum = 1; should_recalc_checksum = 1;
//printf("Replaced Host header!\n"); //printf("Replaced Host header!\n");
} }
@ -1255,7 +1255,7 @@ int main(int argc, char *argv[]) {
if (should_reinject) { if (should_reinject) {
//printf("Re-injecting!\n"); //printf("Re-injecting!\n");
if (should_recalc_checksum) { if (should_recalc_checksum) {
WinDivertHelperCalcChecksums(packet, packetLen, &addr, (UINT64)NULL); WinDivertHelperCalcChecksums(packet, packetLen, &addr, (UINT64)0LL);
} }
WinDivertSend(w_filter, packet, packetLen, &addr, NULL); WinDivertSend(w_filter, packet, packetLen, &addr, NULL);
} }