From patchwork Sat Dec 27 05:24:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 4441 Received: (qmail 18158 invoked by alias); 27 Dec 2014 05:24:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18147 invoked by uid 89); 27 Dec 2014 05:24:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 27 Dec 2014 05:24:35 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBR5OXOS026463 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sat, 27 Dec 2014 00:24:34 -0500 Received: from psique.yyz.redhat.com (dhcp-10-15-16-169.yyz.redhat.com [10.15.16.169]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBR5OXK0003005; Sat, 27 Dec 2014 00:24:33 -0500 From: Sergio Durigan Junior To: GDB Patches Cc: Pedro Alves , Sergio Durigan Junior Subject: [PATCH] Sanitize input_interrupt output Date: Sat, 27 Dec 2014 00:24:23 -0500 Message-Id: <1419657863-13470-1-git-send-email-sergiodj@redhat.com> X-IsSubscribed: yes Hi, This patch is a follow-up of the following discussions: input_interrupt is currently emiting non-printable characters, which is confusing the dg-extract-results.sh script. This is obviously not a good thing, and, by following Pedro's advices here: I adapted the function to print "client connection closed" when it receives a NUL character, or use the "isprint" function to decide how to print the received char. I tested it by running the testcases that were printing the non-printable chars before: gdb.base/gdb-sigterm.exp gdb.threads/non-ldr-exc-1.exp gdb.threads/non-ldr-exc-2.exp gdb.threads/non-ldr-exc-3.exp gdb.threads/non-ldr-exc-4.exp gdb.threads/thread-execl.exp and confirming that they print the right message. I tried a bit to come up with a testcase for this, but failed, and since I did not want to spend too much time on it, I'm sending the patch anyway. Comments are welcome, as usual. gdb/gdbserver/ChangeLog: 2014-12-27 Sergio Durigan Junior * remote-utils.c: Include ctype.h. (input_interrupt): Explicitly handle the case when the char received is the NUL byte. Improve the printing of non-ASCII characters. --- gdb/gdbserver/remote-utils.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 373fc15..0d55cd7 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -23,6 +23,7 @@ #include "tdesc.h" #include "dll.h" #include "rsp-low.h" +#include #if HAVE_SYS_IOCTL_H #include #endif @@ -741,10 +742,18 @@ input_interrupt (int unused) cc = read_prim (&c, 1); - if (cc != 1 || c != '\003' || current_thread == NULL) + if (cc == 0) { - fprintf (stderr, "input_interrupt, count = %d c = %d ('%c')\n", - cc, c, c); + fprintf (stderr, "client connection closed\n"); + return; + } + else if (cc != 1 || c != '\003' || current_thread == NULL) + { + fprintf (stderr, "input_interrupt, count = %d c = %d ", cc, c); + if (isprint (c)) + fprintf (stderr, "('%c')\n", c); + else + fprintf (stderr, "('\\x%02x)\n", c & 0xFF); return; }