Simple reproduction of failure:
#include <gtest/gtest.h> #include <gmock/gmock.h> #include <sys/socket.h> #include <sys/stat.h>
TEST(IsItBroken, recvmsg) { using namespace testing;
enum { server, client, size }; int socket_fd[size]; int const opt = 1;
ASSERT_THAT(socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fd), Eq(0));
auto const msg = "A random message"; send(socket_fd[client], msg, sizeof msg, MSG_DONTWAIT | MSG_NOSIGNAL);
ASSERT_THAT(setsockopt(socket_fd[server], SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt)), Ne(-1));
union { struct cmsghdr cmh; char control[CMSG_SPACE(sizeof(ucred))]; } control_un;
control_un.cmh.cmsg_len = CMSG_LEN(sizeof(ucred)); control_un.cmh.cmsg_level = SOL_SOCKET; control_un.cmh.cmsg_type = SCM_CREDENTIALS;
msghdr msgh; msgh.msg_name = nullptr; msgh.msg_namelen = 0; msgh.msg_iov = nullptr; msgh.msg_iovlen = 0; msgh.msg_control = control_un.control; msgh.msg_controllen = sizeof(control_un.control);
errno = 0;
EXPECT_THAT(recvmsg(socket_fd[server], &msgh, MSG_PEEK), Ne(-1));
for (auto socket : socket_fd) close(socket); }
Simple reproduction of failure:
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <sys/socket.h>
#include <sys/stat.h>
TEST(IsItBroken, recvmsg)
{
using namespace testing;
enum { server, client, size };
int socket_fd[size];
int const opt = 1;
ASSERT_ THAT(socketpair (AF_LOCAL, SOCK_STREAM, 0, socket_fd), Eq(0));
auto const msg = "A random message"; socket_ fd[client] , msg, sizeof msg, MSG_DONTWAIT | MSG_NOSIGNAL);
send(
ASSERT_ THAT(setsockopt (socket_ fd[server] , SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt)), Ne(-1));
union { CMSG_SPACE( sizeof( ucred)) ];
struct cmsghdr cmh;
char control[
} control_un;
control_ un.cmh. cmsg_len = CMSG_LEN( sizeof( ucred)) ; un.cmh. cmsg_level = SOL_SOCKET; un.cmh. cmsg_type = SCM_CREDENTIALS;
control_
control_
msghdr msgh; msg_namelen = 0; msg_control = control_un.control; msg_controllen = sizeof( control_ un.control) ;
msgh.msg_name = nullptr;
msgh.
msgh.msg_iov = nullptr;
msgh.msg_iovlen = 0;
msgh.
msgh.
errno = 0;
EXPECT_ THAT(recvmsg( socket_ fd[server] , &msgh, MSG_PEEK), Ne(-1));
for (auto socket : socket_fd) close(socket);
}