Merge pull request #229 from metrapoliten/fixes

Различные фиксы
This commit is contained in:
Vadim Vetrov
2025-02-07 18:23:48 +03:00
committed by GitHub
5 changed files with 47 additions and 35 deletions

View File

@@ -62,14 +62,18 @@ static int read_file(const char* filename) {
}
ret = fseek(fd, 0, SEEK_END);
if (ret < 0) {
if (ret != 0) {
ret = -errno;
goto close_file;
}
size_t fsize = ftell(fd);
fseek(fd, 0, SEEK_SET);
if (ret < 0) {
long fsize = ftell(fd);
if (fsize == -1L) {
ret = -errno;
goto close_file;
}
ret = fseek(fd, 0, SEEK_SET);
if (ret != 0) {
ret = -errno;
goto close_file;
}
@@ -120,10 +124,10 @@ static int parse_sni_domains(struct domains_list **dlist, const char *domains_st
unsigned int domain_len = (i - j);
const char *domain_startp = domains_str + j;
struct domains_list *edomain = malloc(sizeof(struct domains_list));
*edomain = (struct domains_list){0};
if (edomain == NULL) {
return -ENOMEM;
}
*edomain = (struct domains_list){0};
edomain->domain_len = domain_len;
edomain->domain_name = malloc(domain_len + 1);
@@ -285,6 +289,9 @@ static int parse_fake_custom_payload(
return -EINVAL;
}
unsigned char *custom_buf = malloc(custom_len);
if (custom_buf == NULL) {
return -ENOMEM;
}
for (int i = 0; i < custom_len; i++) {
ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i);
@@ -1242,11 +1249,11 @@ int init_section_config(struct section_config_t **section, struct section_config
#else
def_section = malloc(sizeof(struct section_config_t));
#endif
*def_section = (struct section_config_t)default_section_config;
def_section->prev = prev;
if (def_section == NULL)
if (def_section == NULL)
return -ENOMEM;
*def_section = (struct section_config_t)default_section_config;
def_section->prev = prev;
ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr));
if (ret < 0) {

View File

@@ -502,18 +502,11 @@ drop:
int send_ip4_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
if (poses_sz == 0) {
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
if (!instance_config.send_delayed_packet) {
return -EINVAL;
}
lgtrace_addp("Sent %zu delayed for %d", pktlen, section->seg2_delay);
instance_config.send_delayed_packet(
return instance_config.send_delayed_packet(
packet, pktlen, section->seg2_delay);
return 0;
} else {
lgtrace_addp("Sent %zu bytes", pktlen);
return instance_config.send_raw_packet(
packet, pktlen);
}
@@ -588,18 +581,11 @@ out:
int send_tcp_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
if (poses_sz == 0) {
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
if (!instance_config.send_delayed_packet) {
return -EINVAL;
}
instance_config.send_delayed_packet(
return instance_config.send_delayed_packet(
packet, pktlen, section->seg2_delay);
return 0;
} else {
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
return instance_config.send_raw_packet(
packet, pktlen);
}

View File

@@ -71,7 +71,7 @@ int quic_check_is_initial(const struct quic_lhdr *qch) {
uint32_t qversion;
int ret;
ret = quic_get_version(&qversion, qch);
if (qversion < 0) return 0;
if (ret < 0) return 0;
uint8_t qtype = qch->type;

View File

@@ -82,6 +82,10 @@ int quic_parse_initial_message(
ret = quic_parse_data(quic_payload, quic_plen,
&qch, &qch_len, &qci, &inpayload, &inplen
);
if (ret < 0) {
lgerror(ret, "quic_parse_data");
goto error_nfr;
}
ret = quic_get_version(&qversion, qch);
if (ret < 0) {
@@ -117,10 +121,6 @@ int quic_parse_initial_message(
}
quic_header_len = inpayload - quic_payload;
if (ret < 0) {
lgerror(ret, "quic_parse_data");
goto error_nfr;
}
ret = quic_parse_initial_header(inpayload, inplen, &qich);
if (ret < 0) {

View File

@@ -614,14 +614,33 @@ void *delay_packet_send_fn(void *data) {
}
int delay_packet_send(const unsigned char *data, size_t data_len, unsigned int delay_ms) {
int ret;
struct dps_t *dpdt = malloc(sizeof(struct dps_t));
if (dpdt == NULL) {
return -ENOMEM;
}
*dpdt = (struct dps_t){0};
dpdt->pkt = malloc(data_len);
if (dpdt->pkt == NULL) {
free(dpdt);
return -ENOMEM;
}
memcpy(dpdt->pkt, data, data_len);
dpdt->pktlen = data_len;
dpdt->timer = delay_ms;
pthread_t thr;
pthread_create(&thr, NULL, delay_packet_send_fn, dpdt);
pthread_detach(thr);
pthread_t thr = {0};
ret = pthread_create(&thr, NULL, delay_packet_send_fn, dpdt);
if (ret != 0) {
free(dpdt->pkt);
free(dpdt);
return -ret;
}
ret = pthread_detach(thr);
lgtrace_addp("Scheduled packet send after %d ms", delay_ms);
return 0;