-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security] support.args_from_interpreter_flags() doesn't inherit -I (isolated) flag #78993
Comments
The support.args_from_interpreter_flags() function recreates Python command line arguments from sys.flags, but it omits -I (sys.flags.isolated). Because of that, "./python -I -m test ..." behaves differently than "./python -I -m test -j0 ...": |
Thanks Victor for the details. Can this be classified as an easy issue? I guess the fix will be as below :
Off topic : I don't know why '-I' is not documented as sys.flags.isolated at https://docs.python.org/3.7/library/sys.html#sys.flags . Maybe I will open up a separate issue for this? |
In the C code, sys.flags.isolated clearly documented as linked to the -I option: static PyStructSequence_Field flags_fields[] = {
I expect to get: $ python3 -I -c 'import subprocess; print(subprocess._args_from_interpreter_flags())'
['-I'] instead of: ['-s', '-E'] -I is different from -s -E: it also avoids to add the script directory or an empty string to sys.path. |
Thanks Victor for the details.
With respect to documentation I was talking about '-I' not being documented in the table at https://docs.python.org/3.7/library/sys.html#sys.flags though it's present in the C code and in sys.flags.isolated.
'-I' also implies '-s -E' and hence adding isolated to args_from_interpreter_flags will also return ['-s', '-E', '-I'] as output and hence I suggested modifying the comparison logic. # Since '-I' implies '-s' and '-E' those flags are also set returning '-s -E -I' ./python.exe --help | rg '\-I' ./python.exe -I -c 'import sys; print(sys.flags)' # patching args_from_interpreter_flags to support '-I' would return below ./python.exe -I -c 'import subprocess; print(subprocess._args_from_interpreter_flags())' Thanks |
This looks wrong, I would prefer to only get ['-I']. |
Thanks for bringing this up Karthikeyan, however, could there be another reason why -I would be left out. Also, have you filed an issue for this? Also, Victor and Karthikeyan, since this issue has been categorized as an easy issue, I would like to fix this if none of you have started working on this. |
I couldn't see any related issue for this though the table was changed in 3.7.0
I am not working on this. Feel free to pick it up. |
Thank you Karthikeyan, I'm going to take care of both of these issues. |
Linking this1 here in case someone else stumbles upon this thread. I've created an issue and a PR for the documentation issue regarding the absence of -I flag from the sys.flags table which came into picture from the discussions in this thread. |
From what I understand, this can be done in one of two ways. First, we could edit Line 430 in ad73a9c
Secondly, we could handle this condition in |
As in the docs for -I it implies -s and -E so removing the increment is not a good solution in my opinion and will break code. I don't know how this can be handled since -I sets -s and -E implicitly and _args_from_interpreted_flags just looks for the set flag. This could also get a little complex if we remove -s and -E based on -I since one might pass -I and -s. Maybe we can do an intersection of the command line arguments passes and the set bits in _args_from_interpreted_flags so that only -I remains? Victor prefers -I only and maybe has an approach to solve this? |
You're right Karthikeyan, although I personally think that returning ['-s', '-E', '-I'] should be a plausible solution here since it has been stated explicitly that it implies '-s' and '-E' but I'm still waiting for what Victor has to say on this.
Karthikeyan, do you happen to have a use case where this might come into action? |
I don't have a use case in mind. The comment was that returning '-s -E -I' would need the helper function used in the test to be changed. Thanks |
Sorry for bumping this thread but Victor, could you please share your inputs on this if you have the time for it, thanks. |
I tried to explain how to fix the bug, but nobody came up with a working change 2 months, so I wrote the PR myself. It's an important security issue, since the function is used by multiprocessing and distutils modules to spawn new child processes. |
Ok, the bug is now fixed in Python 3.6, 3.7 and master branches ;-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: