From 0a9d1947a7774902f7118e91f64a53056e01b8f7 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 30 Mar 2016 02:22:58 +0000 Subject: [PATCH] Fix printing of unreadable struct iovec * io.c (tprint_iov_upto): If the first element of iovec array is unreadable, print its address without array markup. * tests/readv.c (main): Check it. --- io.c | 19 +++++++++++++------ tests/readv.c | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/io.c b/io.c index 2075d201..aac93eae 100644 --- a/io.c +++ b/io.c @@ -86,17 +86,23 @@ tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int deco } else { abbrev_end = end; } - tprints("["); + if (addr >= abbrev_end) { + tprints("[...]"); + return; + } for (cur = addr; cur < end; cur += sizeof_iov) { - if (cur > addr) + if (cur > addr) { tprints(", "); - if (cur >= abbrev_end) { - tprints("..."); - break; + if (cur >= abbrev_end) { + tprints("..."); + break; + } } if (umove_ulong_array_or_printaddr(tcp, cur, iov, ARRAY_SIZE(iov))) break; + if (cur <= addr) + tprints("["); tprints("{"); if (decode_iov) { unsigned long len = iov[1]; @@ -108,7 +114,8 @@ tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int deco printaddr(iov[0]); tprintf(", %lu}", iov[1]); } - tprints("]"); + if (cur > addr) + tprints("]"); } void diff --git a/tests/readv.c b/tests/readv.c index ce765ec0..b0603c20 100644 --- a/tests/readv.c +++ b/tests/readv.c @@ -60,7 +60,7 @@ main(void) void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); assert(writev(1, efault, 42) == -1); - tprintf("writev(1, [%p], 42) = -1 EFAULT (%m)\n", efault); + tprintf("writev(1, %p, 42) = -1 EFAULT (%m)\n", efault); assert(readv(0, efault, 42) == -1); tprintf("readv(0, %p, 42) = -1 EFAULT (%m)\n", efault); -- 2.40.0