git: 253d8a1f8a24 - main - tests/unix_seqpacket: test that implied connect doesn't work

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Wed, 28 Feb 2024 22:33:11 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=253d8a1f8a247fc363ab6bad6ed0fa9c7cc25060

commit 253d8a1f8a247fc363ab6bad6ed0fa9c7cc25060
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-02-28 22:32:47 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-02-28 22:32:47 +0000

    tests/unix_seqpacket: test that implied connect doesn't work
    
    Applies both to SOCK_STREAM and SOCK_SEQPACKET.  Put the test in this file
    as it is most advanced one.
    
    Reviewed by:            tuexen
    Differential Revision:  https://reviews.freebsd.org/D43854
---
 tests/sys/kern/unix_seqpacket_test.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c
index cde427401970..e93bdfe7e0b1 100644
--- a/tests/sys/kern/unix_seqpacket_test.c
+++ b/tests/sys/kern/unix_seqpacket_test.c
@@ -527,6 +527,23 @@ ATF_TC_BODY(send_before_accept, tc)
 	close(a);
 }
 
+/* Implied connect is unix/dgram only feature. Fails on stream or seqpacket. */
+ATF_TC_WITHOUT_HEAD(implied_connect);
+ATF_TC_BODY(implied_connect, tc)
+{
+	const struct sockaddr_un *sun;
+	int l, s;
+
+	sun = mk_listening_socket(&l);
+
+	ATF_REQUIRE((s = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) > 0);
+	ATF_REQUIRE(sendto(s, &s, sizeof(s), 0, (struct sockaddr *)sun,
+	    sizeof(*sun)) == -1);
+	ATF_REQUIRE(errno == ENOTCONN);
+	close(l);
+	close(s);
+}
+
 /* accept(2) can receive a connection */
 ATF_TC_WITHOUT_HEAD(accept);
 ATF_TC_BODY(accept, tc)
@@ -1099,6 +1116,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, send_recv_with_connect);
 	ATF_TP_ADD_TC(tp, sendto_recvfrom);
 	ATF_TP_ADD_TC(tp, send_before_accept);
+	ATF_TP_ADD_TC(tp, implied_connect);
 	ATF_TP_ADD_TC(tp, shutdown_send);
 	ATF_TP_ADD_TC(tp, shutdown_send_sigpipe);
 	ATF_TP_ADD_TC(tp, eagain_8k_8k);