From c59297b50b2cca4b4ae6bb65211aa0f57b14916d Mon Sep 17 00:00:00 2001 From: ruti <> Date: Mon, 19 Feb 2024 22:01:25 +0300 Subject: [PATCH] --split-at-host: cancel if host not found --- desync.c | 9 ++++++--- packets.c | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/desync.c b/desync.c index 5f16c9c..efb9d39 100644 --- a/desync.c +++ b/desync.c @@ -171,7 +171,7 @@ int desync(int sfd, char *buffer, size_t bfsize, else if (type == IS_HTTPS && params.tlsrec) { int o = params.tlsrec_pos; if (params.tlsrec_sni) { - o += (host - buffer - 9 - 5); + o += (host - buffer - 5); } else if (o < 0) { o += n; @@ -179,8 +179,11 @@ int desync(int sfd, char *buffer, size_t bfsize, n = part_tls(buffer, bfsize, n, o); } - if (host && params.split_host) { - pos += (host - buffer); + if (params.split_host) { + if (host) + pos += (host - buffer); + else + pos = 0; } else if (pos < 0) { pos += n; diff --git a/packets.c b/packets.c index e388854..6df8c84 100644 --- a/packets.c +++ b/packets.c @@ -232,6 +232,9 @@ ssize_t part_tls(char *buffer, size_t bsize, ssize_t n, int pos) return n; } uint16_t r_sz = ANTOHS(buffer, 3); + if (r_sz < pos) { + return n; + } memmove(buffer + 5 + pos + 5, buffer + 5 + pos, n - (5 + pos)); memcpy(buffer + 5 + pos, buffer, 3);