From bdf82d2087cb66870cb4c1dc6271e0952b6b841c Mon Sep 17 00:00:00 2001 From: wangchen Date: Thu, 3 Aug 2023 10:58:45 +0800 Subject: [PATCH] net/tcp: Return -EINVAL if bind is called more than once Signed-off-by: wangchen --- net/tcp/tcp_conn.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index b9cfa904b0a..1c5ce4eb433 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -325,6 +325,12 @@ static inline int tcp_ipv4_bind(FAR struct tcp_conn_s *conn, net_lock(); + if (conn->lport != 0) + { + net_unlock(); + return -EINVAL; + } + /* Verify or select a local port (network byte order) */ port = tcp_selectport(PF_INET, @@ -390,6 +396,12 @@ static inline int tcp_ipv6_bind(FAR struct tcp_conn_s *conn, net_lock(); + if (conn->lport != 0) + { + net_unlock(); + return -EINVAL; + } + /* Verify or select a local port (network byte order) */ /* The port number must be unique for this address binding */