From patchwork Thu Nov 24 20:43:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vibhav Pant X-Patchwork-Id: 25696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3601640wrr; Thu, 24 Nov 2022 12:44:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6/5JrLJFEQ0Ep98ZgDRmYzypbtSU29DSejj+GT4Jje/+iUa0J7lO7pNp6QJ3nJA/RnOt1k X-Received: by 2002:a05:6402:12d5:b0:469:885b:fcfd with SMTP id k21-20020a05640212d500b00469885bfcfdmr16803782edx.177.1669322679976; Thu, 24 Nov 2022 12:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669322679; cv=none; d=google.com; s=arc-20160816; b=wsvxqkOR6NBIcMF1ktUCaKAnipo88ADh2u5XVQnPRNhB4fusxk4HDx9hbpALNo159z L77mu6yUKXGF6ctUtNqoI05j+p3A24YfWHLqUEmFEkUv+mLSIzKTQLhGwkMr5LwaSD65 TJH7Rd0mdw+uAoOFGkt/iCXBvTEkUgY463B1/kQBKHAEIi4qG5lLPgXbZPrNzTdJ90+s X6xIhV7nmjQhxha7ipqO5dmxsMpjAFFdw0tosZVxZ+9lrpJz0hX3091UPMBqXeCbjPyx Pc5+oZX7dxUZqTkMgnU/WM9HSjW4XZGlM1gV+Il2tvu6awbd46TAIvflk2rrHrF/BpOn G1PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:date:cc:to:subject:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=4cxzqKk6jn69Wi51TQTb4cpoQaWr7cyYx7TJ9SicmbI=; b=YlxZRscaJlY8F27XasCQprnEQA74FkNCw9xHdBL/xl+l1ODhaAp7TY6dNEDY0ByF88 2NK0A5hgszPYFXLpvxa6+KaqH71oiOsqNK+dNqHDJ2Ab4M2dWEiucQdLdcS6BWmrpIsW WKeR7EQ6CPifsS0q6nUUe9k1dwE3bx2VanZ4kigtnzB3vp/Z9de4w9Z7Ifqc0zDQxDz5 ixwSzoXgUlcIbBliJksTG1Els7hukKK7MWrXm3jRqTJev0pz0y8IVhfLVC+XJ9Ak2BSG rKdPQQMcUX5OEMnmwAUyu7S+XWqsk/oa+5IBKKGLn16Qe8aYmWE8ssaLt02O7d+uP/vH ZK6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rByltMtF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c19-20020a50f613000000b004607378ae65si1852989edn.160.2022.11.24.12.44.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 12:44:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rByltMtF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03F4E3885C24 for ; Thu, 24 Nov 2022 20:44:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03F4E3885C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669322679; bh=4cxzqKk6jn69Wi51TQTb4cpoQaWr7cyYx7TJ9SicmbI=; h=Subject:To:Cc:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rByltMtFyyRfA9UkHiTDuIQz6QDDeRPJh/S6t8XcgQNZOjK23MQdNcqiJ3PjZj1iM EZ9gmXX4ocKTUYOohGwSjgwf8Wtf5f9W6CQzdhhydmKwp5HDl45G5k7l6uZez8QKf2 tpV8eUdN8XXBBXgvxJicI20o6o7MxDIWuYvSEv9g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 95DCA38845FC; Thu, 24 Nov 2022 20:43:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 95DCA38845FC Received: by mail-wr1-x436.google.com with SMTP id s5so4041260wru.1; Thu, 24 Nov 2022 12:43:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:date:cc:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4cxzqKk6jn69Wi51TQTb4cpoQaWr7cyYx7TJ9SicmbI=; b=G7f1RHVZkC5O7H3QBcElO3YTndgAG6nG3+ORd+ATzxnPiFLOQGomMuNkh3nUSK39mE oXXMkXXR0dzcLpCdyKAQ3DA8rWpRJZcduFU23rQC8JFf2+VaW+JqmyXGlD7yGmBguRr0 a0g+LION5SEagQTUkimT+wK79DDiLw++ItoSNMZA7ZNbBuizbqA8GE751KSv71Uqd5/A K/GSpI0mdNlTnQGRQ0ArpEre92yD4+LSDuO/DvV7xQN2gYBa8K1E9lel17s8D6/dULSR 70unQI6APnCoDWkVDK8TkC22IAx9qfxlJKBs346//I6XSOvfnRaZAPPnMJcMl+m2BQDV 8ToQ== X-Gm-Message-State: ANoB5pn3Vlw4PicAVrXKlpa4LRmvznqVKEEfQEwMeaPOGon8sb5xD6OD hJZdR1EOJdmqHexOCy1yYbI6k4mcbbsSsQ== X-Received: by 2002:adf:e712:0:b0:241:d309:8e0c with SMTP id c18-20020adfe712000000b00241d3098e0cmr13733316wrm.547.1669322632570; Thu, 24 Nov 2022 12:43:52 -0800 (PST) Received: from [192.168.1.3] ([182.69.176.206]) by smtp.gmail.com with ESMTPSA id fn9-20020a05600c688900b003cf6a55d8e8sm2845169wmb.7.2022.11.24.12.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 12:43:51 -0800 (PST) Message-ID: <5bcb69810185bfa4d614aef0c57fb4641b1ae2eb.camel@gmail.com> Subject: [PATCH] gcc/jit/jit-recording.cc: recording::global::write_to_dump: Avoid crashes when writing psuedo-C for globals with string initializers. To: jit@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Date: Fri, 25 Nov 2022 02:13:34 +0530 User-Agent: Evolution 3.46.1 MIME-Version: 1.0 X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vibhav Pant via Gcc-patches From: Vibhav Pant Reply-To: Vibhav Pant Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750411698351455924?= X-GMAIL-MSGID: =?utf-8?q?1750411698351455924?= If a char * global was initialized with a rvalue from `gcc_jit_context_new_string_literal` containing a format string, dumping the context causes libgccjit to SIGSEGV due to an improperly constructed call to vasprintf. The following code snippet can reproduce the crash: int main(int argc, char **argv) { gcc_jit_context *ctxt = gcc_jit_context_acquire (); gcc_jit_lvalue *var = gcc_jit_context_new_global( ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR), "var"); gcc_jit_global_set_initializer_rvalue( var, gcc_jit_context_new_string_literal(ctxt, "%s")); gcc_jit_context_dump_to_file (ctxt, "output", 0); return 0; } The offending line is jit-recording.cc:4922, where a call to d.write passes the initializer rvalue's debug string to `write` without a format specifier. The attached patch fixes this issue. Thanks, Vibhav From e598a4076b2bff72b4a3cc29d1d70db8c53baf45 Mon Sep 17 00:00:00 2001 From: Vibhav Pant Date: Fri, 25 Nov 2022 02:02:09 +0530 Subject: [PATCH] jit-recording.cc: Dump string literal initializers correctly --- gcc/jit/jit-recording.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 6ae5a667e90..7bb98ddcb42 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -4919,7 +4919,7 @@ recording::global::write_to_dump (dump &d) else if (m_rvalue_init) { d.write (" = "); - d.write (m_rvalue_init->get_debug_string ()); + d.write ("%s", m_rvalue_init->get_debug_string ()); d.write (";\n"); } -- 2.38.1