From patchwork Wed Jan 23 09:52:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Phillips X-Patchwork-Id: 979 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 89629ACA4D96 for ; Wed, 23 Jan 2019 09:52:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00=-1, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,T_DMARC_TESTS_FAIL=0.01 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 23 Jan 2019 09:52:42 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 1297710358BD01; Wed, 23 Jan 2019 09:52:41 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Wed, 23 Jan 2019 09:52:41 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id D09852BEC4; Wed, 23 Jan 2019 09:52:40 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id C97152BE51 for ; Wed, 23 Jan 2019 09:52:37 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Wed, 23 Jan 2019 09:52:36 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 695B410358BCFE for ; Wed, 23 Jan 2019 09:52:33 +0000 (UTC) Received: from oh.not.bad.aye.yeah.nah.nz (oh.not.bad.aye.yeah.nah.nz [52.36.103.82]) by orion.archlinux.org (Postfix) with ESMTP for ; Wed, 23 Jan 2019 09:52:32 +0000 (UTC) Received: by oh.not.bad.aye.yeah.nah.nz (Postfix, from userid 1000) id E1639409B9; Wed, 23 Jan 2019 22:52:29 +1300 (NZDT) Date: Wed, 23 Jan 2019 22:52:20 +1300 From: David Phillips To: pacman-dev@archlinux.org Message-ID: <20190123095220.GA13475@box> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.2 (2019-01-07) Subject: [pacman-dev] [PATCH] libalpm: Check cachedir access before re-creating X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" If users have mounted a filesystem such as sshfs or NFS that doesn't allow root access by default for security reasons, _alpm_filecache_setup will blindly try and re-create the components of the cachedir path, eating EACCES (to be liek mkdir -p). Then, it will return this path as if it is valid when it may not be readable by root, causing alpm_check_downloadspace to trigger a FPE since it assumes the cachedir is R/W and uses fsinfo which may be zero. This patch adds a check before trying to re-create the cachedir in order to determine if creating it will result in EACCES, and outputs a warning if so. It also discards the current cachedir from being considered. This causes a more meaningful and graceful failure than a FPE. --- lib/libalpm/util.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index d33eef2a..d4375593 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -849,12 +849,16 @@ const char *_alpm_filecache_setup(alpm_handle_t *handle) for(i = handle->cachedirs; i; i = i->next) { cachedir = i->data; if(stat(cachedir, &buf) != 0) { - /* cache directory does not exist.... try creating it */ - _alpm_log(handle, ALPM_LOG_WARNING, _("no %s cache exists, creating...\n"), - cachedir); - if(_alpm_makepath(cachedir) == 0) { - _alpm_log(handle, ALPM_LOG_DEBUG, "using cachedir: %s\n", cachedir); - return cachedir; + if (errno == EACCES) { + _alpm_log(handle, ALPM_LOG_WARNING, _("failed to stat %s: %s\n"), cachedir, strerror(errno)); + } else { + /* cache directory does not exist.... try creating it */ + _alpm_log(handle, ALPM_LOG_WARNING, _("no %s cache exists, creating...\n"), + cachedir); + if(_alpm_makepath(cachedir) == 0) { + _alpm_log(handle, ALPM_LOG_DEBUG, "using cachedir: %s\n", cachedir); + return cachedir; + } } } else if(!S_ISDIR(buf.st_mode)) { _alpm_log(handle, ALPM_LOG_DEBUG,