From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 91D9D3858D33 for ; Wed, 25 Oct 2023 12:40:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91D9D3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 91D9D3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698237623; cv=none; b=hER8Fgrdxv7vIySKghmicNGq2UbQP799OmkQNVC+43LzGIpS4yA2Npj29J90weINXlrtMmivLpFqY00XZf1wWhQVD4V5NyYMTxTBTZahsY1FhWtnTyRyonDlto+PvQXModUskEMMBsMsb1tXYYALmEkaHO/lE73TMJhmohpoH8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698237623; c=relaxed/simple; bh=0/P/FOHb+ywFaETFoQYXnJuj77rJtybuCNWCgLS7CSY=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=x/lCrQBVyE8V1WQaQyvX65kAsAnwG+bkQdJLVNmjd3ayk0Uon0wlraqz7cy3ZS/BiUFjdmX7V8XuErb/i54UEKyt9RjNOosYocVuU/PHlhutPOT98U692KHONwtE+i0ffhP0eC+PyivWlpOK8Yt5LIzZFb75QNhktLcMGb6QJNo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698237619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0/P/FOHb+ywFaETFoQYXnJuj77rJtybuCNWCgLS7CSY=; b=QWBYBbMK8uW/hL5JapQVB2mV559ZRtpRFTFtJEZaC7ZjKwpttDxxtHxIMQBLhZAzNTGyId cPBbCgJpIONRZyQ4s1ETJc5zFqojy0L/57MEwTa2rs0IYJXEQok6yTCPbLYgHQ83h2UQ34 i1SafYM9PxKjyV6MDN6ALFIOeruUxzI= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-257-Exzh0kNZMpygVnStvtY_RA-1; Wed, 25 Oct 2023 08:40:17 -0400 X-MC-Unique: Exzh0kNZMpygVnStvtY_RA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-77891f36133so683512285a.0 for ; Wed, 25 Oct 2023 05:40:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698237617; x=1698842417; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0/P/FOHb+ywFaETFoQYXnJuj77rJtybuCNWCgLS7CSY=; b=j0rEuTqaFlhP8fHNxVdUuPZbi6J3C1wir6AYPxMhbTh6JP0vuiCXcmiRz61uTbJkcO ym3XdQBRSkvx6gzhXuh+r82F0rNjDz401JW/R6fmhz2ZhnSjlVeWoFEk16QlJpMP6b/P fgufhZiz3KPSyO5NSMykH64/xMUEHptZuvTJ6hUizXBi/6Ot4FLmg8DyZNYpUrScYQBn iw5ONT031WNOZWzwTM6czNS0VoqgBgwwjqxUPNN1pKLi1BkhSyk8urB0WaZl1MUlxu8m i95h2qQyUDES4+b5djcjKABR3d/+ndtyf9kJHwoFGFVb4TceyYBxk13A2uFcg2t/Xxsb gygg== X-Gm-Message-State: AOJu0YzX5+Q2KrFpXDqgescJkQ/NYlb9S2WMG/i5cuvWMW+lzPJ4VKm5 OFvvjvp0ANzf1jS1XPmHouNRUirhX2/mZWCH4G72Jcf7FB9b/m53ZAr/gAZ2s07Cc7HjJOHsdVE YVBmCIpY= X-Received: by 2002:a05:620a:29d0:b0:775:9041:73dc with SMTP id s16-20020a05620a29d000b00775904173dcmr13664570qkp.16.1698237617210; Wed, 25 Oct 2023 05:40:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCC0RHwVnZ/hDaYlj3CmyahTcoXg1UpkcPRy2+18HLbwvHhyLzAbds6yVIxRKHTywYPcmA3g== X-Received: by 2002:a05:620a:29d0:b0:775:9041:73dc with SMTP id s16-20020a05620a29d000b00775904173dcmr13664555qkp.16.1698237616932; Wed, 25 Oct 2023 05:40:16 -0700 (PDT) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id s1-20020a05620a29c100b007742bc74184sm4153135qkp.110.2023.10.25.05.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 05:40:16 -0700 (PDT) Message-ID: <16a7d8567f7123108a7e773a26728f5921a9b4dc.camel@redhat.com> Subject: Re: [PATCH] gcc/jit/jit-recording.cc: recording::global::write_to_dump: Avoid crashes when writing psuedo-C for globals with string initializers. From: David Malcolm To: Vibhav Pant , jit@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Date: Wed, 25 Oct 2023 08:40:15 -0400 In-Reply-To: <5bcb69810185bfa4d614aef0c57fb4641b1ae2eb.camel@gmail.com> References: <5bcb69810185bfa4d614aef0c57fb4641b1ae2eb.camel@gmail.com> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Fri, 2022-11-25 at 02:13 +0530, Vibhav Pant via Jit wrote: > 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: >=20 > int main(int argc, char **argv) > { > =C2=A0gcc_jit_context *ctxt =3D gcc_jit_context_acquire (); > =C2=A0gcc_jit_lvalue *var =3D gcc_jit_context_new_global( > =C2=A0ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, > =C2=A0gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR), > =C2=A0"var"); > =C2=A0gcc_jit_global_set_initializer_rvalue( > =C2=A0var, gcc_jit_context_new_string_literal(ctxt, "%s")); > =C2=A0gcc_jit_context_dump_to_file (ctxt, "output", 0); > =C2=A0return 0; > } >=20 > 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 for spotting this, and sorry about missing your patch. I've gone ahead and pushed this to trunk (as r14-4923-gac66744d94226a), and will backport it. Dave