From patchwork Tue Oct 11 22:38:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Syromyatnikov X-Patchwork-Id: 9372173 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E3F96607FD for ; Wed, 12 Oct 2016 07:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD50D29CDF for ; Wed, 12 Oct 2016 07:48:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C13D529CED; Wed, 12 Oct 2016 07:48:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 46F9F29CDF for ; Wed, 12 Oct 2016 07:48:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u9C7jXDF014027; Wed, 12 Oct 2016 03:45:34 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u9BMcI9g009472 for ; Tue, 11 Oct 2016 18:38:18 -0400 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9BMcIEW032262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 11 Oct 2016 18:38:18 -0400 Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 953B76333C; Tue, 11 Oct 2016 22:38:17 +0000 (UTC) Received: by mail-lf0-f68.google.com with SMTP id x79so5522176lff.2; Tue, 11 Oct 2016 15:38:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=vKyA1GAM6Xcjxx+59Ax9Zyn3Go+DFiGOqbMnYsa4qFo=; b=KNxyeabOpIV9SLt5nw57aSE+ePo4PKycYRglYEL9E8hAS7qw+Zeqh5ycp34mtYx9cu byOnSStEsHINfUwc9x+uhNd1Oq7QIo+6iAgqZOEeh8uYlDKWn7vHY6tnkwb8YwtP2mP7 vAifmUAXSle9PbtOpByDY7B4EbpU02XJytYiYyPhQ+DLZapGID9CREtiv/i4TyuFeuGW ybUnvjAIG+1GAoFu3eZYemrw3ZVOknloB7mIdMlDNzr4XFefWoipXcav+wJfrHS15AUf ftJSWtbBDmUsD0Tcqcf5lefR64EA0PNSFH0OWLgz0Lb0LoxDfWB9Bcic67D3uHI0uI1x j0Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=vKyA1GAM6Xcjxx+59Ax9Zyn3Go+DFiGOqbMnYsa4qFo=; b=gxpCQsoTZbJmEVJ6XT4T4GjM5jd58Us8RYFYZyAc1dXs4K0UfxPEsY78eY9XXCKgmg Pexb2xDxUwkTIyw1i+yU2wO0XAJwv68wWOQyM/25tatIeGBMnnGsJ+AE7st3yInNr22v /VS4yYuFYpPDDpUqqb0/BvbZrpt/u3kxQbKD1Uu0fveMl9pz8fv55KMSMGFPx7ZNsHd5 Vg3a+YPL+3BYz3wiMN0gOuKRyNFpqh+yyS5089PMQYjalQ7CwsQ7CE748mGjliRfwFjG iB2jrUHe/zZC5ni1bn2grrG7Gm+Rsv10tnWKof5UEA/VENT0UnKKtFnXNUxKvBitG7rs SCQg== X-Gm-Message-State: AA6/9RlLS4xjPr6Zy/aff065b8Ici5hb83dvW8SPlVcv9wjF4KWHN8hePbRFlXvKmD8+eg== X-Received: by 10.25.152.83 with SMTP id a80mr5074416lfe.144.1476225495934; Tue, 11 Oct 2016 15:38:15 -0700 (PDT) Received: from obsidian (broadband-46-188-15-144.2com.net. [46.188.15.144]) by smtp.gmail.com with ESMTPSA id e70sm1543274lji.30.2016.10.11.15.38.15 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 11 Oct 2016 15:38:15 -0700 (PDT) Date: Wed, 12 Oct 2016 01:38:13 +0300 From: Eugene Syromyatnikov To: strace-devel@lists.sourceforge.net Message-ID: <20161011223813.GA8414@obsidian> References: <20161005.192828.566127461630656590.yamato@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161005.192828.566127461630656590.yamato@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Oct 2016 22:38:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Oct 2016 22:38:17 +0000 (UTC) for IP:'209.85.215.68' DOMAIN:'mail-lf0-f68.google.com' HELO:'mail-lf0-f68.google.com' FROM:'evgsyr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.18 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.215.68 mail-lf0-f68.google.com 209.85.215.68 mail-lf0-f68.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Wed, 12 Oct 2016 03:45:31 -0400 Cc: dm-devel@redhat.com, mpatocka@redhat.com, yamato@redhat.com Subject: [dm-devel] [PATCH 1/9] util: Add support for QUOTE_0_TERMINATED in user_style to ptrintstr_ex X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP This enables printing size-limited (expectedly) ASCIZ strings. --- util.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/util.c b/util.c index 23a5fdb..00148d4 100644 --- a/util.c +++ b/util.c @@ -820,13 +820,13 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style) outstr = xmalloc(outstr_size); } - size = max_strlen; + size = max_strlen + 1; if (len == -1) { /* * Treat as a NUL-terminated string: fetch one byte more * because string_quote may look one byte ahead. */ - if (umovestr(tcp, addr, size + 1, str) < 0) { + if (umovestr(tcp, addr, size, str) < 0) { printaddr(addr); return; } @@ -844,11 +844,23 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style) style |= user_style; + if (style & QUOTE_0_TERMINATED) { + if (size) { + --size; + } else { + tprints((len == -1) || (len == 0) ? "\"\"" : "\"\"..."); + return; + } + } + if (size > max_strlen) + size = max_strlen; + /* If string_quote didn't see NUL and (it was supposed to be ASCIZ str * or we were requested to print more than -s NUM chars)... */ ellipsis = (string_quote(str, outstr, size, style) && - (len < 0 || (unsigned long) len > max_strlen)); + ((style & QUOTE_0_TERMINATED) || + (unsigned long) len > max_strlen)); tprints(outstr); if (ellipsis)