Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/syscall Must use CMSG_SPACE instead of CMSG_LEN for co...



details:   https://anonhg.NetBSD.org/src/rev/a698648098ac
branches:  trunk
changeset: 750138:a698648098ac
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Dec 18 21:24:13 2009 +0000

description:
Must use CMSG_SPACE instead of CMSG_LEN for control message buffer.
Fixes test on sparc64 (and possible other alignment-picky ports).
from mlelstv

diffstat:

 tests/syscall/t_cmsg.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (58 lines):

diff -r 7c6962187c0a -r a698648098ac tests/syscall/t_cmsg.c
--- a/tests/syscall/t_cmsg.c    Fri Dec 18 19:20:35 2009 +0000
+++ b/tests/syscall/t_cmsg.c    Fri Dec 18 21:24:13 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_cmsg.c,v 1.12 2009/11/26 17:33:23 pooka Exp $        */
+/*     $NetBSD: t_cmsg.c,v 1.13 2009/12/18 21:24:13 pooka Exp $        */
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -40,7 +40,7 @@
        if (rump_sys_socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1)
                atf_tc_fail("rump_sys_socket");
 
-       cmp = malloc(CMSG_LEN(sizeof(int)));
+       cmp = malloc(CMSG_SPACE(sizeof(int)));
 
        iov.iov_base = &fd;
        iov.iov_len = sizeof(int);
@@ -54,7 +54,7 @@
        msg.msg_name = NULL;
        msg.msg_namelen = 0;
        msg.msg_control = cmp;
-       msg.msg_controllen = CMSG_LEN(sizeof(int));
+       msg.msg_controllen = CMSG_SPACE(sizeof(int));
 
        /*
         * ERROR HERE: trying to pass invalid fd
@@ -128,14 +128,14 @@
            sizeof(MAGICSTRING))
                atf_tc_fail_errno("pipe write"); /* XXX: errno */
 
-       cmp = malloc(CMSG_LEN(sizeof(int)));
+       cmp = malloc(CMSG_SPACE(sizeof(int)));
 
        iov.iov_base = &storage;
        iov.iov_len = sizeof(int);
 
        cmp->cmsg_level = SOL_SOCKET;
        cmp->cmsg_type = SCM_RIGHTS;
-       cmp->cmsg_len = CMSG_LEN(sizeof(int));
+       cmp->cmsg_len = CMSG_SPACE(sizeof(int));
 
        msg.msg_iov = &iov;
        msg.msg_iovlen = 1;
@@ -149,6 +149,13 @@
        if (rump_sys_sendmsg(s2, &msg, 0) == -1)
                atf_tc_fail_errno("sendmsg failed");
 
+       /*
+        * We will read to the same cmsg space.  Overwrite the space
+        * with an invalid fd to make sure we get an explicit error
+        * if we don't manage to read the fd.
+        */
+       *(int *)CMSG_DATA(cmp) = -1;
+
        /* switch back to original proc */
        rump_pub_lwp_switch(l1);
 



Home | Main Index | Thread Index | Old Index