From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26316 invoked by alias); 2 Feb 2015 17:43:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 26307 invoked by uid 89); 2 Feb 2015 17:43:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 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; Mon, 02 Feb 2015 17:43:18 +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 t12HhGgF031867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 2 Feb 2015 12:43:16 -0500 Received: from [10.10.116.40] ([10.10.116.40]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t12HhGYR011771 for ; Mon, 2 Feb 2015 12:43:16 -0500 Message-ID: <54CFB72F.1090907@redhat.com> Date: Mon, 02 Feb 2015 17:43:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for abi_tag sanity checking Content-Type: multipart/mixed; boundary="------------050105060000070304050901" X-SW-Source: 2015-02/txt/msg00070.txt.bz2 This is a multi-part message in MIME format. --------------050105060000070304050901 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 315 One of the EDG guys pointed out to me that we weren't doing any sanity checking on the arguments to the abi_tag attribute. This patch adds checks to require that the arguments be strings containing valid identifiers, so they work appropriately in mangled names. Tested x86_64-pc-linux-gnu, applying to trunk. --------------050105060000070304050901 Content-Type: text/x-patch; name="tag-diag.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tag-diag.patch" Content-length: 2215 commit 3c9202343aca0b0a9d74fee4e6843000f3a612cf Author: Jason Merrill Date: Fri Jan 30 07:45:02 2015 -0500 * tree.c (handle_abi_tag_attribute): Diagnose invalid arguments. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index afb57a3..c51e42d 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3501,6 +3501,50 @@ static tree handle_abi_tag_attribute (tree* node, tree name, tree args, int flags, bool* no_add_attrs) { + for (tree arg = args; arg; arg = TREE_CHAIN (arg)) + { + tree elt = TREE_VALUE (arg); + if (TREE_CODE (elt) != STRING_CST + || (!same_type_ignoring_top_level_qualifiers_p + (strip_array_types (TREE_TYPE (elt)), + char_type_node))) + { + error ("arguments to the %qE attribute must be narrow string " + "literals", name); + goto fail; + } + const char *begin = TREE_STRING_POINTER (elt); + const char *end = begin + TREE_STRING_LENGTH (elt); + for (const char *p = begin; p != end; ++p) + { + char c = *p; + if (p == begin) + { + if (!ISALPHA (c) && c != '_') + { + error ("arguments to the %qE attribute must contain valid " + "identifiers", name); + inform (input_location, "%<%c%> is not a valid first " + "character for an identifier", c); + goto fail; + } + } + else if (p == end - 1) + gcc_assert (c == 0); + else + { + if (!ISALNUM (c) && c != '_') + { + error ("arguments to the %qE attribute must contain valid " + "identifiers", name); + inform (input_location, "%<%c%> is not a valid character " + "in an identifier", c); + goto fail; + } + } + } + } + if (TYPE_P (*node)) { if (!OVERLOAD_TYPE_P (*node)) diff --git a/gcc/testsuite/g++.dg/abi/abi-tag13.C b/gcc/testsuite/g++.dg/abi/abi-tag13.C new file mode 100644 index 0000000..34e8da3 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/abi-tag13.C @@ -0,0 +1,5 @@ +const char *foo = "bar"; +void __attribute((abi_tag(foo))) f1() {} // { dg-error "abi_tag" } +void __attribute((abi_tag(L"foo"))) f2(); // { dg-error "abi_tag" } +void __attribute((abi_tag("3foo"))) f3(); // { dg-error "abi_tag" } +void __attribute((abi_tag(1))) f5(); // { dg-error "abi_tag" } --------------050105060000070304050901--