aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanno Böck <hanno@gentoo.org>2023-04-24 16:03:28 +0200
committerSam James <sam@gentoo.org>2023-04-29 05:41:18 +0100
commit4cc3e2d39a39b422074de49e88261cdf717292d5 (patch)
tree2d2249b454a327704b2511aac232e6ad05fbd7b3
parentbin: Rename all _E_*DESTTREE_ variables to __E_*DESTTREE (diff)
downloadportage-4cc3e2d39a39b422074de49e88261cdf717292d5.tar.gz
portage-4cc3e2d39a39b422074de49e88261cdf717292d5.tar.bz2
portage-4cc3e2d39a39b422074de49e88261cdf717292d5.zip
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@gentoo.org> Closes: https://github.com/gentoo/portage/pull/1025 Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-xbin/dispatch-conf3
1 files changed, 2 insertions, 1 deletions
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):