From patchwork Sat Mar 12 22:58:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Gregory X-Patchwork-Id: 2051 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.28) for (single-drop); Sat, 12 Mar 2022 22:58:34 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id MKFWKJklLWLW6QIAK+/4rw (envelope-from ) for ; Sat, 12 Mar 2022 22:58:33 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id 5DD37DE39F3; Sat, 12 Mar 2022 22:58:32 +0000 (UTC) Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id 4B720DD97D4; Sat, 12 Mar 2022 22:58:32 +0000 (UTC) X-Original-To: pacman-dev@lists.archlinux.org Delivered-To: pacman-dev@lists.archlinux.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lists.archlinux.org (Postfix) with ESMTPS id 8102CDD97C4 for ; Sat, 12 Mar 2022 22:58:30 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id w4so10600267ply.13 for ; Sat, 12 Mar 2022 14:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ygPwhHmS6dHbYXSvgqHkv36uf8njHreK/ZOk49XABLY=; b=AxXgFSsWLwCM9+7xynPX9aTzGXGgRiflvhuTxUeC3zqnjlEDZZpshZN3fEbEUH48td NXE13STmrExPa8vcWciqClgtNK2jtBYaDbyiaV8+HC77xYMlk6JOH+pPX3LAVGzPF/9B Zsb3ZzAy9HrNLuqV4Q8n1wWt2YgIepsGLcZUtyq63Z3lSyHnck7FxRJcyeWLtZVMHWyO j7hnmaOC9AaOOlddnIzSU4fvGBwnRXEu2ZXVLhQDvKyChgyZ7gX32ngLkaViRrH5F627 nudOpUKEEkEJ25qlofAvIPhOaM/87UPVBxtmkJAY+S9IP4KhlpUk8jODb1cKYBsZIFL/ fI+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ygPwhHmS6dHbYXSvgqHkv36uf8njHreK/ZOk49XABLY=; b=MSwbb/9m1XgLpFOi4mENd9vBZgNhzxKYx6EGbqOHsbjg0sy3mQEI73UXRVvqoCVnuQ xXIp3g8adVvKopoCWMHxWgmCIKSgPEtZxrN7AdqLj2xgC2Uq0yFIvBxoL+iEmnOj6X5G NG0DLEu6fjVjz3akOO+Gh246BjigFKcmHsVSepqEgqjtmVOmPoK8crLRPCJXA1rTbePt NE3fu69dzFmrKJNeoJjGXcPkaZ6oB296VvwaIXkULjlzwbBMeKvBJu0DEz1QfetVmDMi Bb/QPkgnKrj6qO2pkh5/UcUJsN/GZ8S+7AWloZVmGA2FTItqDUt8AzMFi6iXVglreJC9 xfrQ== X-Gm-Message-State: AOAM5303PQjTdIW0mvKm4ShUAahCizttjC1lQ2Wm5j1bjbfWPFVgO9ss yis55jqCPAWBI9Nh6rUNeDx9B1wXr/M= X-Google-Smtp-Source: ABdhPJzgfsi+jRQ6gauSEfE4SsByMYz9W+8Bx55FJtKG1jqJsLe/ds0L94+hu1Pm2ddcoB1E3TKnAw== X-Received: by 2002:a17:903:1c4:b0:151:f3f2:d54d with SMTP id e4-20020a17090301c400b00151f3f2d54dmr17529972plh.10.1647125908246; Sat, 12 Mar 2022 14:58:28 -0800 (PST) Received: from localhost.localdomain ([98.47.65.14]) by smtp.gmail.com with ESMTPSA id r4-20020a638f44000000b0038105776895sm6237871pgn.76.2022.03.12.14.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Mar 2022 14:58:27 -0800 (PST) From: Andrew Gregory To: pacman-dev@lists.archlinux.org Cc: Andrew Gregory Subject: [PATCH] set bash env variables before running scripts Date: Sat, 12 Mar 2022 14:58:13 -0800 Message-Id: <20220312225813.206988-1-andrew.gregory.8@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-dev-bounces@lists.archlinux.org Sender: "pacman-dev" X-Spamd-Result: default: False [-1.41 / 15.00]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; R_MISSING_CHARSET(0.50)[]; MAILLIST(-0.20)[mailman]; RCVD_IN_DNSWL_MED(-0.20)[2a01:4f9:c010:9eb4::1:from]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1:c]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FROM_HAS_DN(0.00)[]; FROM_NEQ_ENVFROM(0.00)[andrewgregory8@gmail.com,pacman-dev-bounces@lists.archlinux.org]; TAGGED_RCPT(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; NEURAL_HAM(-0.00)[-1.000]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::62a:received]; RCVD_COUNT_FIVE(0.00)[5]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; FORGED_SENDER_MAILLIST(0.00)[] Authentication-Results: mail.archlinux.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=AxXgFSsW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: 5DD37DE39F3 X-Rspamd-Server: mail.archlinux.org Bash sources user configuration files under a number of conditions that can cause issues with scripts when bash is used as the scriptlet shell. Bash assumes it's being run under rsh/ssh if stdin is connected to a socket and sources the user bashrc unless the environment variable $SHLVL is >= 2. Commit 6a4c6a02de9b45abe4c0f78c4f5d14d92d3359d6 switched from pipes to sockets when communicating with child processes to work around SIGPIPE issues. Normally $SHLVL would be inherited from the shell running pacman, but operations involving scriptlets are generally run with sudo which does not let the $SHLVL variable through unless specifically configured to. Similarly $BASH_ENV can cause bash to source user-specified configuration files if set. https://lists.gnu.org/archive/html/help-bash/2022-02/msg00082.html Signed-off-by: Andrew Gregory --- Not entirely sure we should actually be unsetting $BASH_ENV, but Chet recommended it. lib/libalpm/util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 06e0fe7f2..7340ce832 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -659,6 +659,11 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[], "/", strerror(errno)); exit(1); } + /* bash thinks it's being run under rsh/ssh if stdin is a socket and + * sources ~/.bashrc unles SHLVL is > 1 */ + setenv("SHLVL", "1", 0); + /* bash sources $BASH_ENV when run non-interactively */ + unsetenv("BASH_ENV"); umask(0022); _alpm_reset_signals(); execv(cmd, argv);