Skip to content

Commit dbe0007

Browse files
Shrey-Nhroncokblurb-it[bot]vstinner
authored
gh-145417: Do not preserve SELinux context when copying venv scripts (#145454)
Co-authored-by: Miro Hrončok <miro@hroncok.cz> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 2cd0ddf commit dbe0007

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Lib/test/test_venv.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import os.path
1212
import pathlib
1313
import re
14+
import shlex
1415
import shutil
1516
import subprocess
1617
import sys
1718
import sysconfig
1819
import tempfile
19-
import shlex
2020
from test.support import (captured_stdout, captured_stderr,
2121
skip_if_broken_multiprocessing_synchronize, verbose,
2222
requires_subprocess, is_android, is_apple_mobile,
@@ -373,6 +373,16 @@ def create_contents(self, paths, filename):
373373
with open(fn, 'wb') as f:
374374
f.write(b'Still here?')
375375

376+
@unittest.skipUnless(hasattr(os, 'listxattr'), 'test requires os.listxattr')
377+
def test_install_scripts_selinux(self):
378+
"""
379+
gh-145417: Test that install_scripts does not copy SELinux context
380+
when copying scripts.
381+
"""
382+
with patch('os.listxattr') as listxattr_mock:
383+
venv.create(self.env_dir)
384+
listxattr_mock.assert_not_called()
385+
376386
def test_overwrite_existing(self):
377387
"""
378388
Test creating environment in an existing directory.

Lib/venv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def skip_file(f):
581581
'may be binary: %s', srcfile, e)
582582
continue
583583
if new_data == data:
584-
shutil.copy2(srcfile, dstfile)
584+
shutil.copy(srcfile, dstfile)
585585
else:
586586
with open(dstfile, 'wb') as f:
587587
f.write(new_data)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:mod:`venv`: Prevent incorrect preservation of SELinux context
2+
when copying the ``Activate.ps1`` script. The script inherited
3+
the SELinux security context of the system template directory,
4+
rather than the destination project directory.

0 commit comments

Comments
 (0)