From 692add84c5b36d5acd929b4507091e5516d10d44 Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Tue, 23 Jul 2024 22:24:43 +0300 Subject: [PATCH] Add more error handlers --- youtubeUnblock.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/youtubeUnblock.c b/youtubeUnblock.c index 2fd334b..9e3b4f1 100644 --- a/youtubeUnblock.c +++ b/youtubeUnblock.c @@ -218,7 +218,14 @@ static int ipv4_frag(struct pkt_buff *pktb, size_t payload_offset, nfq_ip_set_checksum(f2_hdr); *frag1 = pktb_alloc(AF_INET, buff1, f1_dlen, 0); + if (*frag1 == NULL) + return -1; + *frag2 = pktb_alloc(AF_INET, buff2, f2_dlen, 0); + if (*frag2 == NULL) { + pktb_free(*frag1); + return -1; + } return 0; } @@ -291,7 +298,15 @@ static int tcp4_frag(struct pkt_buff *pktb, size_t payload_offset, nfq_tcp_compute_checksum_ipv4(s2_tcph, s2_hdr); *seg1 = pktb_alloc(AF_INET, buff1, s1_dlen, 0); + if (*seg1 == NULL) + return -1; + *seg2 = pktb_alloc(AF_INET, buff2, s2_dlen, 0); + if (*seg2 == NULL) { + pktb_free(*seg1); + return -1; + } + return 0; } @@ -308,9 +323,12 @@ static int send_raw_socket(struct pkt_buff *pktb) { struct pkt_buff *buff2; #ifdef USE_TCP_SEGMENTATION - tcp4_frag(pktb, AVAILABLE_MTU-128, &buff1, &buff2); + if (tcp4_frag(pktb, AVAILABLE_MTU-128, &buff1, &buff2) < 0) + return -1; #else - ipv4_frag(pktb, AVAILABLE_MTU-128, &buff1, &buff2); + if (ipv4_frag(pktb, AVAILABLE_MTU-128, &buff1, &buff2) < 0) + return -1; + #endif int sent = 0; @@ -335,7 +353,6 @@ static int send_raw_socket(struct pkt_buff *pktb) { return sent; } - struct iphdr *iph = nfq_ip_get_hdr(pktb); if (iph == NULL) return -1; @@ -350,6 +367,7 @@ static int send_raw_socket(struct pkt_buff *pktb) { if (tcph != NULL) { sin_port = tcph->dest; + errno = 0; } else if (udph != NULL) { sin_port = udph->dest; } else { @@ -643,9 +661,8 @@ static int process_packet(const struct packet_data packet) { size_t ipd_offset = ((char *)data - (char *)tcph) + vrd.sni_offset; size_t mid_offset = ipd_offset + vrd.sni_len / 2; mid_offset += 8 - mid_offset % 8; + - - if (ipv4_frag(pktb, mid_offset, &frag1, &frag2) < 0) { perror("ipv4_frag"); goto fallback;