From patchwork Sun Aug 5 16:59:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 953550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483197-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wyW4XT5/"; dkim-atps=neutral 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 41k6TY2N1kz9s0n for ; Mon, 6 Aug 2018 02:59:58 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=LEYkAuZFqeJGcgE0dPXCzJpiIy69cexYZOy8GjphfNjfgzvUDzZIZ dY65aQzcYAozZk2/G76C3aLJ/Td5M9DZ3R3xBJmge+3Ps1CAmZjUdoht8yird62b seHq8D3SMGT+Xe4749J1jvr/rSSSa4W75WHmiAmHXM5CzkuhxsXU5I= 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:from :to:subject:date:message-id:content-type:mime-version; s= default; bh=YO3RNyQG7SzCrdBkvHzQTVHP4Ec=; b=wyW4XT5/rcSooboEzj/V Ly0m/l8GlAhtWNdeuWoyMOWrAuWXvPaFowHmPdV/0/FC8uusP4dxXFboHigEeDrm 23zEafFLknO2ScJeF5Hxv1aylIdHwlNb9p/4ZkzzZQC7bWlrBWr6BOOxSL+crRxy T7ajUDrK8NSdNMbQMCbtVco= Received: (qmail 10684 invoked by alias); 5 Aug 2018 16:59:50 -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 10667 invoked by uid 89); 5 Aug 2018 16:59:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=adapted, jit, recording, reg-tested X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-oln040092066064.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.92.66.64) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 05 Aug 2018 16:59:46 +0000 Received: from DB5EUR01FT020.eop-EUR01.prod.protection.outlook.com (10.152.4.58) by DB5EUR01HT056.eop-EUR01.prod.protection.outlook.com (10.152.5.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.1038.3; Sun, 5 Aug 2018 16:59:43 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com (10.152.4.55) by DB5EUR01FT020.mail.protection.outlook.com (10.152.4.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.1038.3 via Frontend Transport; Sun, 5 Aug 2018 16:59:43 +0000 Received: from AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243]) by AM5PR0701MB2657.eurprd07.prod.outlook.com ([fe80::b1fe:1b4f:88c3:5243%9]) with mapi id 15.20.1017.019; Sun, 5 Aug 2018 16:59:43 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , David Malcolm Subject: [PATCH] Fix not properly nul-terminated string constants in JIT Date: Sun, 5 Aug 2018 16:59:42 +0000 Message-ID: received-spf: None (protection.outlook.com: hotmail.de does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=bernd.edlinger@hotmail.de; MIME-Version: 1.0 Hi! My other patch with adds assertions to varasm.c regarding correct nul termination of sting literals did make these incorrect string constants in JIT frontend fail. The string constants are not nul terminated if their length exceeds 200 characters. The test cases do not use strings of that size where that would make a difference. But using a fixed index type is clearly wrong. This patch removes the fixed char[200] array type from playback::context, and uses build_string_literal instead of using build_string directly. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. 2018-08-05 Bernd Edlinger * jit-playback.c (playback::context::context): Remove m_char_array_type_node. (playback::context::new_string_literal): Use build_string_literal. (playback::context::replay): Remove m_char_array_type_node. * jit-playback.h (playback::context::m_char_array_type_node): Remove. diff -pur gcc/jit/jit-playback.c gcc/jit/jit-playback.c --- gcc/jit/jit-playback.c 2018-06-28 09:08:01.000000000 +0200 +++ gcc/jit/jit-playback.c 2018-08-05 15:58:15.815403219 +0200 @@ -81,7 +81,6 @@ playback::context::context (recording::c : log_user (ctxt->get_logger ()), m_recording_ctxt (ctxt), m_tempdir (NULL), - m_char_array_type_node (NULL), m_const_char_ptr (NULL) { JIT_LOG_SCOPE (get_logger ()); @@ -617,16 +616,9 @@ playback::rvalue * playback::context:: new_string_literal (const char *value) { - tree t_str = build_string (strlen (value), value); - gcc_assert (m_char_array_type_node); - TREE_TYPE (t_str) = m_char_array_type_node; - - /* Convert to (const char*), loosely based on - c/c-typeck.c: array_to_pointer_conversion, - by taking address of start of string. */ - tree t_addr = build1 (ADDR_EXPR, m_const_char_ptr, t_str); + tree t_str = build_string_literal (strlen (value) + 1, value); - return new rvalue (this, t_addr); + return new rvalue (this, t_str); } /* Construct a playback::rvalue instance (wrapping a tree) for a @@ -2633,10 +2625,6 @@ playback::context:: replay () { JIT_LOG_SCOPE (get_logger ()); - /* Adapted from c-common.c:c_common_nodes_and_builtins. */ - tree array_domain_type = build_index_type (size_int (200)); - m_char_array_type_node - = build_array_type (char_type_node, array_domain_type); m_const_char_ptr = build_pointer_type (build_qualified_type (char_type_node, diff -pur gcc/jit/jit-playback.h gcc/jit/jit-playback.h --- gcc/jit/jit-playback.h 2018-01-03 11:03:58.000000000 +0100 +++ gcc/jit/jit-playback.h 2018-08-05 15:58:52.988918367 +0200 @@ -316,7 +316,6 @@ private: auto_vec m_functions; auto_vec m_globals; - tree m_char_array_type_node; tree m_const_char_ptr; /* Source location handling. */