]> granicus.if.org Git - strace/commitdiff
msghdr.c: limit SCM_RIGHTS output in abbrev mode
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 2 Jul 2016 21:14:26 +0000 (21:14 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 2 Jul 2016 21:14:26 +0000 (21:14 +0000)
* msghdr.c (print_scm_rights): Do not print more than max_strlen
descriptors in abbrev mode.
* tests/msg_control.c (DEFAULT_STRLEN): New macro.
(print_fds): Use it.
(test_scm_rights3): New function.
(main): Use it to test SCM_RIGHTS output in abbrev mode.
* tests/msg_control-v.c: New file.
* tests/msg_control-v.test: New test.
* tests/.gitignore: Add msg_control-v.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add msg_control-v.test.

msghdr.c
tests/.gitignore
tests/Makefile.am
tests/msg_control-v.c [new file with mode: 0644]
tests/msg_control-v.test [new file with mode: 0755]
tests/msg_control.c

index c4d8aef38ce7311d719dab54ce95a79a0ad3b190..0f9ba7145dd885aeec9de424ed7a6b56569c74e0 100644 (file)
--- a/msghdr.c
+++ b/msghdr.c
@@ -66,6 +66,10 @@ print_scm_rights(struct tcb *tcp, const void *cmsg_data, const size_t data_len)
        for (i = 0; i < nfds; ++i) {
                if (i)
                        tprints(", ");
+               if (abbrev(tcp) && i >= max_strlen) {
+                       tprints("...");
+                       break;
+               }
                printfd(tcp, fds[i]);
        }
 
index 1ca49ca42f63a85ea4ea29a21e26244d580bdba4..fecd592c9754ebc746433d91ed9670c0782aba84 100644 (file)
@@ -138,6 +138,7 @@ mount
 move_pages
 mq
 msg_control
+msg_control-v
 munlockall
 nanosleep
 net-accept-connect
index 51c2c7e7fa3f36d2a0e181ce8b46f183512819e0..fdc3b817882f0c90bcb58ce35c5a6144960de5e2 100644 (file)
@@ -192,6 +192,7 @@ check_PROGRAMS = \
        move_pages \
        mq \
        msg_control \
+       msg_control-v \
        munlockall \
        nanosleep \
        net-accept-connect \
@@ -505,6 +506,7 @@ DECODER_TESTS = \
        move_pages.test \
        mq.test \
        msg_control.test \
+       msg_control-v.test \
        munlockall.test \
        nanosleep.test \
        net-icmp_filter.test \
diff --git a/tests/msg_control-v.c b/tests/msg_control-v.c
new file mode 100644 (file)
index 0000000..d2a5653
--- /dev/null
@@ -0,0 +1,3 @@
+/* This file is part of msg_control-v strace test. */
+#define VERBOSE_MSGHDR
+#include "msg_control.c"
diff --git a/tests/msg_control-v.test b/tests/msg_control-v.test
new file mode 100755 (executable)
index 0000000..41f9842
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check verbose decoding of struct msghdr ancillary data.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -v -a21 -e trace=sendmsg
index 4e0c258ef39503fff1d3996936194ba3327a406d..cecd5e8d28a2ca51bc4a103a48bed13d58c224a2 100644 (file)
@@ -60,6 +60,8 @@ get_cmsghdr(void *const page, const size_t len)
        return page - CMSG_ALIGN(len);
 }
 
+#define DEFAULT_STRLEN 32
+
 static void
 print_fds(const struct cmsghdr *const cmsg, const size_t cmsg_len)
 {
@@ -74,6 +76,12 @@ print_fds(const struct cmsghdr *const cmsg, const size_t cmsg_len)
        for (i = 0; i < nfd; ++i) {
                if (i)
                        printf(", ");
+#ifndef VERBOSE_MSGHDR
+               if (i >= DEFAULT_STRLEN) {
+                       printf("...");
+                       break;
+               }
+#endif
                printf("%d", fdp[i]);
        }
        printf("]");
@@ -194,6 +202,33 @@ test_scm_rights2(struct msghdr *const mh,
               (unsigned long) msg_controllen, rc, errno2name());
 }
 
+static void
+test_scm_rights3(struct msghdr *const mh, void *const page, const size_t nfds)
+{
+       const size_t len = CMSG_SPACE(sizeof(int) * nfds);
+       struct cmsghdr *cmsg = get_cmsghdr(page, len);
+
+       cmsg->cmsg_len = CMSG_LEN(sizeof(int) * nfds);
+       cmsg->cmsg_level = SOL_SOCKET;
+       cmsg->cmsg_type = SCM_RIGHTS;
+       int *fdp = (int *) CMSG_DATA(cmsg);
+       size_t i;
+       for (i = 0; i < nfds; ++i)
+               fdp[i] = i;
+
+       mh->msg_control = cmsg;
+       mh->msg_controllen = len;
+
+       int rc = sendmsg(-1, mh, 0);
+       printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL"
+              ", msg_iovlen=0, msg_control=[{cmsg_len=%u"
+              ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS",
+              (unsigned) cmsg->cmsg_len);
+       print_fds(cmsg, cmsg->cmsg_len);
+       printf("}], msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n",
+              (unsigned long) len, rc, errno2name());
+}
+
 static void
 print_security(const struct cmsghdr *const cmsg, const size_t cmsg_len)
 {
@@ -339,6 +374,10 @@ test_sol_socket(struct msghdr *const mh, void *const page)
                }
        }
 
+       test_scm_rights3(mh, page, DEFAULT_STRLEN - 1);
+       test_scm_rights3(mh, page, DEFAULT_STRLEN);
+       test_scm_rights3(mh, page, DEFAULT_STRLEN + 1);
+
        test_unknown_type(mh, page, VAL_STR(SOL_SOCKET), "SCM_???");
 }