Message ID | 20220816114857.1632691-1-slyich@gmail.com |
---|---|
State | Committed |
Commit | 2b403297b111c990c331b5bbb6165b061ad2259b |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83A433858418 for <patchwork@sourceware.org>; Tue, 16 Aug 2022 11:49:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83A433858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660650578; bh=fJOxrGCVzY3q0JeKDgUmHyzPh6N35ws9LKI3dW6gIdw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Go2DSnv82ruBNdu/e/4bpX0b9lskuk5E9Clm9XeYrGLABl2EnAItIUQAuKRtm0ig4 VnpxDMAh4mTZldzFAty644nViHu8CUhykXVPpCTVGNgvqYlNTkzRZYDdsoTLQ4+kYQ 7s4KR/2Dls3SuK07Uee9ztsz8WKYW0yJJW4WPz0I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id C6A0E3858C2D for <gcc-patches@gcc.gnu.org>; Tue, 16 Aug 2022 11:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6A0E3858C2D Received: by mail-wm1-x329.google.com with SMTP id h204-20020a1c21d5000000b003a5b467c3abso8676378wmh.5 for <gcc-patches@gcc.gnu.org>; Tue, 16 Aug 2022 04:49:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=fJOxrGCVzY3q0JeKDgUmHyzPh6N35ws9LKI3dW6gIdw=; b=18n+3YjVj656/I6R4O9HUu/stCfqbH4VEK7tDz8v/+ateyYe2hWSmIX+8tlEKjgyrO IKWa40cFPLnkAGNlWQNa5BgqxxRuLaOc1UoYRpEchUF0/WlGsrM3axTg62p42alfOx9S /WAO4CFe+Q+KbmPgXPjERjImDiG/CzcYBTXy6W4UNt88bb+w2elCfRyNeJxdKKDuQZ2B dg7GT6KaNUvpD/UC5C66iYOPprs6JTSTUqSCTmT2cZDW+4B/KPXdVFEac8EccHaG/owc C1pXFFy9n0yH3f7RmsfELVl8h2I7whkiQybK32bOWIA95f1DXiv3MQRgjwBw7x+DNl2B IBrA== X-Gm-Message-State: ACgBeo2IqJyQd5YlwYNkLTmmE87IlCz4xJTlKTJ0WzHUR2Tl1us8joPi WEBNzi4t+GF0BZ/j0Fpvnh2jorMYrPo= X-Google-Smtp-Source: AA6agR5jl/0+lYBNQH7Kr+0kkbvz5YYm9/GUbKcQsW7C9ifEszVxzPbrcEiBxWWSnaeF70JZjgSzyg== X-Received: by 2002:a05:600c:4e49:b0:3a5:dd23:90d7 with SMTP id e9-20020a05600c4e4900b003a5dd2390d7mr9582716wmq.41.1660650547369; Tue, 16 Aug 2022 04:49:07 -0700 (PDT) Received: from nz.home (host81-129-83-151.range81-129.btcentralplus.com. [81.129.83.151]) by smtp.gmail.com with ESMTPSA id g6-20020a5d4886000000b0021e9fafa601sm9825596wrq.22.2022.08.16.04.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 04:49:06 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id A9F3965B9DD48; Tue, 16 Aug 2022 12:49:05 +0100 (BST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] driver: fix environ corruption after putenv() [PR106624] Date: Tue, 16 Aug 2022 12:48:57 +0100 Message-Id: <20220816114857.1632691-1-slyich@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Sergei Trofimovich via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Sergei Trofimovich <slyich@gmail.com> Cc: Sergei Trofimovich <siarheit@google.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
driver: fix environ corruption after putenv() [PR106624]
|
|
Commit Message
Sergei Trofimovich
Aug. 16, 2022, 11:48 a.m. UTC
From: Sergei Trofimovich <siarheit@google.com>
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.
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(-)
Comments
On 8/16/22 13:48, Sergei Trofimovich wrote: > From: Sergei Trofimovich <siarheit@google.com> > > 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. */
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. */