From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1512692-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 225E615ACFC
	for <garchives@archives.gentoo.org>; Sat, 29 Apr 2023 04:44:35 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 42858E0886;
	Sat, 29 Apr 2023 04:44:34 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(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 pigeon.gentoo.org (Postfix) with ESMTPS id BF631E0884
	for <gentoo-commits@lists.gentoo.org>; Sat, 29 Apr 2023 04:44:33 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(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 smtp.gentoo.org (Postfix) with ESMTPS id 9B900340D24
	for <gentoo-commits@lists.gentoo.org>; Sat, 29 Apr 2023 04:44:32 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id E8307A36
	for <gentoo-commits@lists.gentoo.org>; Sat, 29 Apr 2023 04:44:30 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1682743278.4cc3e2d39a39b422074de49e88261cdf717292d5.sam@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/dispatch-conf
X-VCS-Directories: bin/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: 4cc3e2d39a39b422074de49e88261cdf717292d5
X-VCS-Branch: master
Date: Sat, 29 Apr 2023 04:44:30 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 03a42d09-979e-4fc7-b99f-f08c6f79b221
X-Archives-Hash: b970c98fe4a171f385c51ee384c8746a

commit:     4cc3e2d39a39b422074de49e88261cdf717292d5
Author:     Hanno Böck <hanno <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 24 14:03:28 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Apr 29 04:41:18 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=4cc3e2d3

dispatch-conf: Avoid race when accessing log file

First creating the file and then running chmod creates a security
risk where a user could access the file. Avoid this by enforcing
the file permissions via umask.

Signed-off-by: Hanno Böck <hanno <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/1025
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/dispatch-conf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index 3dbfb0ed6..154b26ff5 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -119,8 +119,9 @@ class dispatch:
             if os.path.isfile(self.options["log-file"]) or not os.path.exists(
                 self.options["log-file"]
             ):
+                old_umask = os.umask(0o077)
                 open(self.options["log-file"], "w").close()  # Truncate it
-                os.chmod(self.options["log-file"], 0o600)
+                os.umask(old_umask)
 
         pager = self.options.get("pager")
         if pager is None or not cmd_var_is_valid(pager):