-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only delete first sys.path entry in the stage-2 bootstrap if PYT…
…HONSAFEPATH is unset or unsupported (#2418) Unnconditionally deleting the first `sys.path` entry on the stage-2 bootstrap incorrecly removes a valid search path on Python 3.11 and above, since `PYTHONSAFEPATH` is already unconditionally set in stage-1. It should be deleted only if it is unset or unsupported. Fixes #2318 --------- Co-authored-by: Richard Levasseur <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
- Loading branch information
1 parent
096a04f
commit 5eb139f
Showing
6 changed files
with
102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test") | ||
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT") | ||
|
||
py_reconfig_test( | ||
name = "no_unsafe_paths_3.10_test", | ||
srcs = ["test.py"], | ||
bootstrap_impl = "script", | ||
main = "test.py", | ||
python_version = "3.10", | ||
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, | ||
) | ||
|
||
py_reconfig_test( | ||
name = "no_unsafe_paths_3.11_test", | ||
srcs = ["test.py"], | ||
bootstrap_impl = "script", | ||
main = "test.py", | ||
python_version = "3.11", | ||
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
|
||
class NoUnsafePathsTest(unittest.TestCase): | ||
def test_no_unsafe_paths_in_search_path(self): | ||
# Based on sys.path documentation, the first item added is the zip | ||
# archive | ||
# (see: https://docs.python.org/3/library/sys_path_init.html) | ||
# | ||
# We can use this as a marker to verify that during bootstrapping, | ||
# (1) no unexpected paths were prepended, and (2) no paths were | ||
# accidentally dropped. | ||
# | ||
major, minor, *_ = sys.version_info | ||
archive = f"python{major}{minor}.zip" | ||
|
||
# < Python 3.11 behaviour | ||
if (major, minor) < (3, 11): | ||
# Because of https://github.com/bazelbuild/rules_python/blob/0.39.0/python/private/stage2_bootstrap_template.py#L415-L436 | ||
self.assertEqual(os.path.dirname(sys.argv[0]), sys.path[0]) | ||
self.assertEqual(os.path.basename(sys.path[1]), archive) | ||
# >= Python 3.11 behaviour | ||
else: | ||
self.assertEqual(os.path.basename(sys.path[0]), archive) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters