diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2025-08-29 22:11:31 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-09-11 17:03:45 +0200 |
commit | 660cd6907e14a41ad9bc77d317140c70ab416fce (patch) | |
tree | 8838202ae6d655376394c201ed76aba8e8899021 | |
parent | 25f93545e7232a7dab9a022862514778c18bc85e (diff) | |
download | passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar.gz passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar.bz2 passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar.lz passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar.xz passt-660cd6907e14a41ad9bc77d317140c70ab416fce.tar.zst passt-660cd6907e14a41ad9bc77d317140c70ab416fce.zip |
tcp: Cast operands of sequence comparison macros to uint32_t before using them
Otherwise, passing signed types causes automatic promotion of the
result of the subtractions as well, which is not what we want, as
these macros rely on unsigned 32-bit arithmetic.
The next patch introduces a ssize_t operand for SEQ_LE, illustrating
the issue.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Tested-by: Paul Holzinger <pholzing@redhat.com>
Reviewed-by: Jon Maloy <jmaloy@redhat.com>
-rw-r--r-- | tcp_internal.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tcp_internal.h b/tcp_internal.h index 9dae688..65144a8 100644 --- a/tcp_internal.h +++ b/tcp_internal.h @@ -18,10 +18,14 @@ sizeof(struct ipv6hdr), \ sizeof(uint32_t)) -#define SEQ_LE(a, b) ((b) - (a) < MAX_WINDOW) -#define SEQ_LT(a, b) ((b) - (a) - 1 < MAX_WINDOW) -#define SEQ_GE(a, b) ((a) - (b) < MAX_WINDOW) -#define SEQ_GT(a, b) ((a) - (b) - 1 < MAX_WINDOW) +#define SEQ_LE(a, b) \ + ((uint32_t)(b) - (uint32_t)(a) < MAX_WINDOW) +#define SEQ_LT(a, b) \ + ((uint32_t)(b) - (uint32_t)(a) - 1 < MAX_WINDOW) +#define SEQ_GE(a, b) \ + ((uint32_t)(a) - (uint32_t)(b) < MAX_WINDOW) +#define SEQ_GT(a, b) \ + ((uint32_t)(a) - (uint32_t)(b) - 1 < MAX_WINDOW) #define FIN (1 << 0) #define SYN (1 << 1) |