From 029d9797672ce8aabd269626dc2c7d72ac055983 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 30 Jun 2016 22:20:56 +0000 Subject: [PATCH] msghdr.c: fix printing SCM_RIGHTS array * msghdr.c (print_scm_rights): Do not print array elements outside bounds defined by struct cmsghdr.cmsg_len. --- msghdr.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/msghdr.c b/msghdr.c index b377be94..5ebaeaa6 100644 --- a/msghdr.c +++ b/msghdr.c @@ -59,20 +59,20 @@ print_scm_rights(struct tcb *tcp, const void *cmsg_data, const size_t data_len) { const int *fds = cmsg_data; - const char *end = (const char *) cmsg_data + data_len; - bool seen = false; + const size_t nfds = data_len / sizeof(*fds); + size_t i; - if (sizeof(*fds) > data_len) + if (!nfds) return; tprints(", cmsg_data=["); - while ((const char *) fds < end) { - if (seen) + + for (i = 0; i < nfds; ++i) { + if (i) tprints(", "); - else - seen = true; - printfd(tcp, *fds++); + printfd(tcp, fds[i]); } + tprints("]"); } -- 2.40.0