From patchwork Sat May 9 18:13:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 470363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 37FE1140218 for ; Sun, 10 May 2015 04:13:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=OsfevFT2; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=Sp8nNyGXjl+x7LEzEdV7vCM2hrFowBaxhB35YkVa//ElZl CeKFTdR9YSgqNA8MU5Zm2y0DgS0jePKQ7CKxyMbS4dfm4i5VuUMXXLk8rGrFlXBI oiPgYnkaHpBnsxl8BGj0WOWpVeknYMJK6HJDB+PUtfWx+5QZNyAP4rPYKUOH0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=KJIMKEjCqeajTDCb3Rn8QmOpOSM=; b=OsfevFT2ktOIQDGEv0CD 4f1M7NFSh+cEd7Z4DImiyZiY4vXHTgwAJ03ZxgC+GPCLnjZRBNNJNFqGRs41zHIz ZiR1UKEmSPoAdCzly/qlWlC9Cl0s4cMLKEiljwz/ojEMNrK9kuM6Zrb/3DxLIpLI Y6AbyqcUBO5XG/XI7ipyUS0= Received: (qmail 97401 invoked by alias); 9 May 2015 18:13:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 97391 invoked by uid 89); 9 May 2015 18:13:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qc0-f174.google.com Received: from mail-qc0-f174.google.com (HELO mail-qc0-f174.google.com) (209.85.216.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 09 May 2015 18:13:46 +0000 Received: by qcbgy10 with SMTP id gy10so51601062qcb.3 for ; Sat, 09 May 2015 11:13:44 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.229.54.196 with SMTP id r4mr4759771qcg.15.1431195224626; Sat, 09 May 2015 11:13:44 -0700 (PDT) Received: by 10.229.215.4 with HTTP; Sat, 9 May 2015 11:13:44 -0700 (PDT) Date: Sat, 9 May 2015 20:13:44 +0200 Message-ID: Subject: [PATCH] D demangle: Correctly decode white or non-printable characters From: Iain Buclaw To: gcc-patches D templates can have string literals encoded inside them, which can also include tabs, newlines, and other whitespace characters. For example: return getHost!q{ auto he = gethostbyname(toStringz(param)); }(name); In this case, rather than decoding and writing out every character directly, whitespace or other non-printable characters should be represented as escape sequences. --- libiberty/ChangeLog: 2015-05-09 Iain Buclaw * d-demangle.c (dlang_parse_string): Represent embedded whitespace or non-printable characters as hex or escape sequences. * testsuite/d-demangle-expected: Add test for templates with tabs and newlines embedded into the signature. --- diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index bb481c0..fa01767 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -931,7 +931,38 @@ dlang_parse_string (string *decl, const char *mangled) char a = ascii2hex (mangled[0]); char b = ascii2hex (mangled[1]); char val = (a << 4) | b; - string_appendn (decl, &val, 1); + + /* Sanitize white and non-printable characters. */ + switch (val) + { + case ' ': + string_append (decl, " "); + break; + case '\t': + string_append (decl, "\\t"); + break; + case '\n': + string_append (decl, "\\n"); + break; + case '\r': + string_append (decl, "\\r"); + break; + case '\f': + string_append (decl, "\\f"); + break; + case '\v': + string_append (decl, "\\v"); + break; + + default: + if (ISPRINT (val)) + string_appendn (decl, &val, 1); + else + { + string_append (decl, "\\x"); + string_appendn (decl, mangled, 2); + } + } } else return NULL; diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 2aeacb8..b023f6d 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -934,3 +934,7 @@ serenity.persister.Sqlite.SqlitePersister!(serenity.persister.Sqlite.__unittest6 --format=dlang _D4test4mainFZv5localMFZi test.main().local() +# +--format=dlang +_D3std6socket12InternetHost221__T13getHostNoSyncVAyaa96_0a09202020206175746f2078203d2068746f6e6c28706172616d293b0a09202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e74294164647265737346616d696c792e494e4554293b0a09TkZ13getHostNoSyncMFkZb +std.socket.InternetHost.getHostNoSync!("\n\t auto x = htonl(param);\n\t auto he = gethostbyaddr(&x, 4, cast(int)AddressFamily.INET);\n\t", uint).getHostNoSync(uint)