From: Dmitry V. Levin Date: Sat, 2 Jul 2016 21:14:26 +0000 (+0000) Subject: msghdr.c: limit SCM_RIGHTS output in abbrev mode X-Git-Tag: v4.13~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d35d5ecc4d8ac1bd3617e6f5f85ca738041130eb;p=strace msghdr.c: limit SCM_RIGHTS output in abbrev mode * 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. --- diff --git a/msghdr.c b/msghdr.c index c4d8aef3..0f9ba714 100644 --- 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]); } diff --git a/tests/.gitignore b/tests/.gitignore index 1ca49ca4..fecd592c 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -138,6 +138,7 @@ mount move_pages mq msg_control +msg_control-v munlockall nanosleep net-accept-connect diff --git a/tests/Makefile.am b/tests/Makefile.am index 51c2c7e7..fdc3b817 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..d2a5653a --- /dev/null +++ b/tests/msg_control-v.c @@ -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 index 00000000..41f98428 --- /dev/null +++ b/tests/msg_control-v.test @@ -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 diff --git a/tests/msg_control.c b/tests/msg_control.c index 4e0c258e..cecd5e8d 100644 --- a/tests/msg_control.c +++ b/tests/msg_control.c @@ -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_???"); }