git: 88e12ccd9afc - releng/15.1 - tests/socket_afinet: Fix the bind_connected_port test
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 07 May 2026 20:40:22 UTC
The branch releng/15.1 has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=88e12ccd9afc55d8e5f66e0fefb0ea71ccb91476
commit 88e12ccd9afc55d8e5f66e0fefb0ea71ccb91476
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-04-20 15:07:20 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-05-07 20:39:59 +0000
tests/socket_afinet: Fix the bind_connected_port test
The test verifies that a socket can bind to a local address assigned by
connect(2) to a different socket. It was however trying to bind to the
wrong address, and the check of the result was inverted, so this went
unnoticed. It also needs to set SO_REUSEADDR for this to succeed.
Approved by: re (cperciva)
Reported by: glebius
MFC after: 1 week
(cherry picked from commit d3d0466cae546254c50c80cf3e0c060bbbbba53c)
(cherry picked from commit 9e8d7d83ecfbf8b34b785d7981a29dda567d0bc6)
---
tests/sys/netinet/socket_afinet.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tests/sys/netinet/socket_afinet.c b/tests/sys/netinet/socket_afinet.c
index 9c718fc5a901..56d98c7b3241 100644
--- a/tests/sys/netinet/socket_afinet.c
+++ b/tests/sys/netinet/socket_afinet.c
@@ -516,6 +516,7 @@ bind_connected_port_test(const atf_tc_t *tc, int domain)
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct sockaddr *sinp;
+ socklen_t slen;
int error, sd[3], tmp;
bool res;
@@ -554,16 +555,15 @@ bind_connected_port_test(const atf_tc_t *tc, int domain)
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
error = connect(sd[1], sinp, sinp->sa_len);
ATF_REQUIRE_MSG(error == 0, "connect failed: %s", strerror(errno));
- tmp = accept(sd[0], NULL, NULL);
+ slen = sinp->sa_len;
+ tmp = accept(sd[0], sinp, &slen);
ATF_REQUIRE_MSG(tmp >= 0, "accept failed: %s", strerror(errno));
- ATF_REQUIRE(close(sd[0]) == 0);
- sd[0] = tmp;
/* bind() should succeed even from an unprivileged user. */
- res = child_bind(tc, SOCK_STREAM, sinp, 0, false);
- ATF_REQUIRE(!res);
- res = child_bind(tc, SOCK_STREAM, sinp, 0, true);
- ATF_REQUIRE(!res);
+ res = child_bind_priv(tc, SOCK_STREAM, sinp, SO_REUSEADDR);
+ ATF_REQUIRE(res);
+ res = child_bind_unpriv(tc, SOCK_STREAM, sinp, SO_REUSEADDR);
+ ATF_REQUIRE(res);
}
/*