pypa / pypa/setuptools

Windows launcher doesn't quote the executable

Open
#622 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Triage
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

In run on line 305 in launcher.c, the quoted executable path is added to the args array (i.e. *newargsp++ = quoted(ptr)), but this is subsequently ignored by join_executable_and_args. Instead it uses the unquoted executable path. Thus if Python is installed to "C:\Program Files", this will mistakenly execute "C:\Program.exe" if it exists.

For example, here are the executable and args parameters passed to join_executable_and_args:

0:000> ?? (char *)@rcx
char * 0x000001d6`aefbe100
 "C:\Program Files\Python35\python.exe"

0:000> ?? ((char **)@rdx)[0]
char * 0x000001d6`aefb4140
 ""C:\Program Files\Python35\python.exe""
0:000> ?? ((char **)@rdx)[1]
char * 0x000001d6`aefb9aa0
 ""C:\Program Files\Python35\Scripts\hello-script.py""

And here is the resulting command line passed to CreateProcessA:

Breakpoint 1 hit
KERNELBASE!CreateProcessA:
00007ffb`9ef0ca00 4c8bdc          mov     r11,rsp
0:000> ?? (char *)@rdx
char * 0x000001d6`aefb6a30
 "C:\Program Files\Python35\python.exe "C:\Program Files\Python35\Scripts\hello-script.py""

join_executable_and_args should just be join_args since the quoted executable is already the first item in args.

I'd prefer that setuptools abandoned this old launcher code to instead use the simple launcher from distlib, which supports Unicode, a job object, and embedded scripts. pip uses distlib's launcher for entry points in wheel packages.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in launcher.c around line 305 and inspect join_executable_and_args, comparing the quoted executable already present in args with the value passed to CreateProcessA. Reproduce the Windows path-with-spaces case and verify that the resulting command line preserves the quoted executable; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.