From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D58133858C20 for ; Tue, 16 Aug 2022 11:59:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D58133858C20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A450F337A2; Tue, 16 Aug 2022 11:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1660651167; h=from:from:reply-to: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=incVXxgTUjVb0C2LN/Iw9Iq3gozFrp+SD5w82TvNHXU=; b=Ia3YqhiWAxSaPmwczFK/loS9aDZ6ows0KMOLD/wpIoqEFHcZKg4N2vhZKSviCerpD5nVhc CWVGgSd/qjMymmgfUq6pBKYZ/mY1s4Z3ZkKJYdTSnrvr49M35y7DZk/SLK2afvV8GYoi8z xkdmK4N8kZZDCIAPx4FH8Jai6Xw7a+8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1660651167; h=from:from:reply-to: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=incVXxgTUjVb0C2LN/Iw9Iq3gozFrp+SD5w82TvNHXU=; b=/6NXhNGSn9JiiXQTfSxaNDTOiH2bYxgvQVE8W//2CuAswCMWaQ55G9iTTGwkVb4wpIkqoc nkROSkZ3o07L6YBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8CEAB139B7; Tue, 16 Aug 2022 11:59:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id XgoKH5+G+2JRQAAAMHmgww (envelope-from ); Tue, 16 Aug 2022 11:59:27 +0000 Message-ID: <6aa569c8-20c3-354a-34b7-8fcaf1d6c070@suse.cz> Date: Tue, 16 Aug 2022 13:59:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH] driver: fix environ corruption after putenv() [PR106624] Content-Language: en-US To: Sergei Trofimovich , gcc-patches@gcc.gnu.org Cc: Sergei Trofimovich References: <20220816114857.1632691-1-slyich@gmail.com> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= In-Reply-To: <20220816114857.1632691-1-slyich@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Tue, 16 Aug 2022 11:59:30 -0000 On 8/16/22 13:48, Sergei Trofimovich wrote: > From: Sergei Trofimovich > > The bug appeared afte r13-2010-g1270ccda70ca09 "Factor out > jobserver_active_p" slightly changed `putenv()` use from allocating > to non-allocating: > > -xputenv (concat ("MAKEFLAGS=", dup, NULL)); > +xputenv (jinfo.skipped_makeflags.c_str ()); > > `xputenv()` (and `putenv()`) don't copy strings and only store the > pointer in the `environ` global table. As a result `environ` got > corrupted as soon as `jinfo.skipped_makeflags` store got deallocated. > > This started causing bootstrap crashes in `execv()` calls: > > xgcc: fatal error: cannot execute '/build/build/./prev-gcc/collect2': execv: Bad address > > The change restores memory allocation for `xputenv()` argument. Thanks for the patch. I think it's an obvious fix, please install it. Martin > > gcc/ > > PR driver/106624 > * gcc (driver::detect_jobserver): Allocate storage xputenv() > argument using xstrdup(). > --- > gcc/gcc.cc | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/gcc.cc b/gcc/gcc.cc > index cac11c1a117..75ca0ece1a4 100644 > --- a/gcc/gcc.cc > +++ b/gcc/gcc.cc > @@ -9182,7 +9182,7 @@ driver::detect_jobserver () const > { > jobserver_info jinfo; > if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ()) > - xputenv (jinfo.skipped_makeflags.c_str ()); > + xputenv (xstrdup (jinfo.skipped_makeflags.c_str ())); > } > > /* Determine what the exit code of the driver should be. */