From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74990 invoked by alias); 14 Sep 2017 19:33:16 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 74970 invoked by uid 89); 14 Sep 2017 19:33:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients 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 ESMTP; Thu, 14 Sep 2017 19:33:14 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76012C00477B; Thu, 14 Sep 2017 19:33:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 76012C00477B Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm@redhat.com Received: from c64.redhat.com (ovpn-112-36.phx2.redhat.com [10.3.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67EF86F12A; Thu, 14 Sep 2017 19:33:12 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: David Malcolm Subject: [committed] Fix crash accessing builtins in sanitizer.def and after (PR jit/82174) Date: Sun, 01 Jan 2017 00:00:00 -0000 Message-Id: <1505419774-35690-1-git-send-email-dmalcolm@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 14 Sep 2017 19:33:13 +0000 (UTC) X-IsSubscribed: yes X-SW-Source: 2017-q3/txt/msg00015.txt.bz2 Calls to gcc_jit_context_get_builtin_function that accessed builtins in sanitizer.def and after (or failed to match any builtin) led to a crash accessing a NULL builtin name. The entries with the NULL name came from these lines in sanitizer.def: /* This has to come before all the sanitizer builtins. */ DEF_BUILTIN_STUB(BEGIN_SANITIZER_BUILTINS, (const char *)0) [...snip...] /* This has to come after all the sanitizer builtins. */ DEF_BUILTIN_STUB(END_SANITIZER_BUILTINS, (const char *)0) This patch updates jit-builtins.c to cope with such entries, fixing the crash. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu; takes jit.sum from 9769 to 9789 PASS results. Committed to trunk as r252769. gcc/jit/ChangeLog: PR jit/82174 * jit-builtins.c (matches_builtin): Ignore entries with a NULL name. gcc/testsuite/ChangeLog: PR jit/82174 * jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c: New test case. --- gcc/jit/jit-builtins.c | 5 ++++- ..._context_get_builtin_function-unknown-builtin.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c index 7840915..35c4db0 100644 --- a/gcc/jit/jit-builtins.c +++ b/gcc/jit/jit-builtins.c @@ -68,7 +68,10 @@ matches_builtin (const char *in_name, const struct builtin_data& bd) { const bool debug = 0; - gcc_assert (bd.name); + + /* Ignore entries with a NULL name. */ + if (!bd.name) + return false; if (debug) fprintf (stderr, "seen builtin: %s\n", bd.name); diff --git a/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c b/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c new file mode 100644 index 0000000..b1e389c --- /dev/null +++ b/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c @@ -0,0 +1,22 @@ +#include +#include + +#include "libgccjit.h" + +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + gcc_jit_context_get_builtin_function (ctxt, + "this_is_not_a_builtin"); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_VALUE (result, NULL); + + CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), + "builtin \"this_is_not_a_builtin\" not found"); +} -- 1.8.5.3