Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Oct 2019 23:35:23 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353332 - head/tests/sys/kern
Message-ID:  <201910082335.x98NZNIe058783@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Oct  8 23:35:23 2019
New Revision: 353332
URL: https://svnweb.freebsd.org/changeset/base/353332

Log:
  Add a regression test for r353331.
  
  MFC after:	1 week
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/tests/sys/kern/unix_passfd_test.c

Modified: head/tests/sys/kern/unix_passfd_test.c
==============================================================================
--- head/tests/sys/kern/unix_passfd_test.c	Tue Oct  8 23:34:48 2019	(r353331)
+++ head/tests/sys/kern/unix_passfd_test.c	Tue Oct  8 23:35:23 2019	(r353332)
@@ -620,6 +620,77 @@ ATF_TC_BODY(copyout_rights_error, tc)
 	closesocketpair(fd);
 }
 
+/*
+ * Verify that we can handle empty rights messages.  Try sending two SCM_RIGHTS
+ * messages with a single call, one empty and one containing a single FD.
+ */
+ATF_TC_WITHOUT_HEAD(empty_rights_message);
+ATF_TC_BODY(empty_rights_message, tc)
+{
+	struct iovec iov;
+	struct msghdr msghdr;
+	char *cm, message[CMSG_SPACE(0) + CMSG_SPACE(sizeof(int))];
+	ssize_t len;
+	int error, fd[2], putfd;
+
+	domainsocketpair(fd);
+	devnull(&putfd);
+
+	/*
+	 * First, try sending an empty message followed by a non-empty message.
+	 */
+	cm = message;
+	putfds(cm, -1, 0);
+	cm += CMSG_SPACE(0);
+	putfds(cm, putfd, 1);
+
+	memset(&msghdr, 0, sizeof(msghdr));
+	iov.iov_base = NULL;
+	iov.iov_len = 0;
+	msghdr.msg_control = message;
+	msghdr.msg_controllen = sizeof(message);
+	msghdr.msg_iov = &iov;
+	msghdr.msg_iovlen = 1;
+
+	len = sendmsg(fd[0], &msghdr, 0);
+	ATF_REQUIRE_MSG(len == 0, "sendmsg failed: %s", strerror(errno));
+
+	/* Only the non-empty message should be received. */
+	len = recvmsg(fd[1], &msghdr, 0);
+	ATF_REQUIRE_MSG(len == 0, "recvmsg failed: %s", strerror(errno));
+	ATF_REQUIRE(msghdr.msg_controllen = CMSG_SPACE(sizeof(int)));
+	error = close((int *)CMSG_DATA(msghdr.msg_control));
+	ATF_REQUIRE_MSG(error == 0, "close failed: %s", strerror(errno));
+
+	/*
+	 * Now try sending with the non-empty message before the empty message.
+	 */
+	cm = message;
+	putfds(cm, putfd, 1);
+	cm += CMSG_SPACE(sizeof(int));
+	putfds(cm, -1, 0);
+
+	memset(&msghdr, 0, sizeof(msghdr));
+	iov.iov_base = NULL;
+	iov.iov_len = 0;
+	msghdr.msg_control = message;
+	msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
+	msghdr.msg_iov = &iov;
+	msghdr.msg_iovlen = 1;
+
+	len = sendmsg(fd[0], &msghdr, 0);
+	ATF_REQUIRE_MSG(len == 0, "sendmsg failed: %s", strerror(errno));
+
+	/* Only the non-empty message should be received. */
+	len = recvmsg(fd[1], &msghdr, 0);
+	ATF_REQUIRE_MSG(len == 0, "recvmsg failed: %s", strerror(errno));
+	ATF_REQUIRE(msghdr.msg_controllen = CMSG_SPACE(sizeof(int)));
+	error = close((int *)CMSG_DATA(msghdr.msg_control));
+	ATF_REQUIRE_MSG(error == 0, "close failed: %s", strerror(errno));
+
+	(void)close(putfd);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -633,6 +704,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, rights_creds_payload);
 	ATF_TP_ADD_TC(tp, truncated_rights);
 	ATF_TP_ADD_TC(tp, copyout_rights_error);
+	ATF_TP_ADD_TC(tp, empty_rights_message);
 
 	return (atf_no_error());
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910082335.x98NZNIe058783>