From 3eb19cfd8a7c03920aeecae6692048429288af88 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 15 Mar 2022 23:17:44 +0100 Subject: tcp, udp, util: Enforce 24-bit limit on socket numbers This should never happen, but there are no formal guarantees: ensure socket numbers are below SOCKET_MAX. Signed-off-by: Stefano Brivio --- tcp_splice.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tcp_splice.c') diff --git a/tcp_splice.c b/tcp_splice.c index cb8df7b..d374785 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -418,6 +418,14 @@ static int tcp_splice_connect(struct ctx *c, struct tcp_splice_conn *conn, const struct sockaddr *sa; socklen_t sl; + if (sock_conn < 0) + return -errno; + + if (sock_conn > SOCKET_MAX) { + close(sock_conn); + return -EIO; + } + conn->b = sock_conn; if (s < 0) -- cgit v1.2.3