Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-99442: Fix handling in py.exe launcher when argv[0] does not include a file extension#99542

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
zooba merged 2 commits intopython:mainfromzooba:gh-99442
Nov 18, 2022

Conversation

@zooba
Copy link
Member

@zoobazooba commentedNov 16, 2022
edited
Loading

Comment on lines +498 to +500
// the argument have no effect. A quoted argv0 must start and end
// with a double quote character; otherwise, it ends at the first
// ' ' or '\t'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Technically speaking, any part of argv0 may be quoted. E.g.C:\"path to"\"py.exe" is parsed asC:\path to\py.exe by the crt. Being quoted just prevents tab or space from terminating the argument.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please see the associated bug (which I just fixed, because I put the wrong ID in the title originally).

We're following CreateProcess rules here, because it's going to be passed to CreateProcess.

Copy link
Contributor

@eryksuneryksunNov 18, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@ChrisDenton, The C runtime's more general parsing ofargv[0] (i.e. multiple quoted parts terminated by space or tab) is only relevant if the executable path is passed explicitly toCreateProcessW() inlpApplicationName. IfCreateProcessW() is called withlpApplicationName asNULL, as the launcher does, then the API parses the command to run fromlpCommandLine. If the command line begins with a double quote, the API consumes all characters up to the next double quote or the end of the command line. If the command line doesn't begin with a double quote, the API tokenizes on space and tab characters, repeatedly searching until it finds a non-directory file.

For example, if the command line isr'C:\Program Files\Python311\python.exe', the API will execute "C:\Program.exe" if it exists. If the command line isr'"C:\Program Files\Python311\python.exe"spam', the API will execute "C:\Program Files\Python311\python.exe" if it exists. Note that there's an inconsistency with the C runtime's quoting rules. The CRT always splits arguments on an unquoted space or tab. For example:

>>> script='import sys; print(sys.orig_argv)'>>> subprocess.call(fr'"{sys.executable}"spam -c "{script}"')['C:\\Program Files\\Python311\\python.exespam', '-c', 'import sys; print(sys.orig_argv)']0

The API executed "python.exe", not "python.exespam".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, that inconsistency is what worried me. As far as I understand it, no normalization is being performed in the python code so the inconsistency remains? So the CRT andCreateProcessW will be understanding the arguments differently?

@zoobazooba changed the titlegh-99370: Fix handling in py.exe launcher when argv[0] does not include a file extensiongh-99442: Fix handling in py.exe launcher when argv[0] does not include a file extensionNov 17, 2022
@zoobazooba merged commita220c6d intopython:mainNov 18, 2022
@miss-islington
Copy link
Contributor

Thanks@zooba for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@zoobazooba deleted the gh-99442 branchNovember 18, 2022 14:15
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 18, 2022
… include a file extension (pythonGH-99542)(cherry picked from commita220c6d)Co-authored-by: Steve Dower <steve.dower@python.org>
@bedevere-bot
Copy link

GH-99579 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelNov 18, 2022
zooba pushed a commit that referenced this pull requestNov 18, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eryksuneryksuneryksun left review comments

+1 more reviewer

@ChrisDentonChrisDentonChrisDenton left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@zooba@miss-islington@bedevere-bot@eryksun@ChrisDenton

[8]ページ先頭

©2009-2025 Movatter.jp