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-129294: use winapi to determine win version before invoking cmd.exe#129295

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

Open
tomergert wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromtomergert:feature/improve_win_ver_recognition

Conversation

tomergert
Copy link

@tomergerttomergert commentedJan 25, 2025
edited by bedevere-appbot
Loading

Improve platform module: use rtlGetVersion to determine win version before trying to use cmd.exe

…before trying to create a process using cmd.exe ver"
@ghost
Copy link

ghost commentedJan 25, 2025
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@@ -110,7 +110,7 @@

"""

__version__ = '1.0.9'
__version__ = '1.0.10'
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be updated?

Suggested change
__version__='1.0.10'
__version__='1.0.9'

It was updated a couple of months ago in#122547, but the previous change was 10 years ago (b9f4fea), and there have been lots of updates in the past decade that didn't change it:

https://github.com/python/cpython/commits/main/Lib/platform.py

Copy link
Member

@terryjreedyterryjreedyJan 26, 2025
edited by hugovk
Loading

Choose a reason for hiding this comment

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

Is the module__version__ attribute really still needed? I thought that these were obsolete. If kept, is the use defined anywhere in a manner that would say when to bump it?

Copy link
Author

Choose a reason for hiding this comment

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

As I understand it just wasn't kept properly. Each change should increase the version (path, minor, major as needed).

@terryjreedy
Copy link
Member

The issue quoted existing codefor cmd in ('ver', 'command /c ver', 'cmd /c ver'):. Are all 3 options still needed for the Windows versions we currently support? Are any of these specific to Win95, ..., WinXp, etc?

@tomergert
Copy link
Author

The issue quoted existing codefor cmd in ('ver', 'command /c ver', 'cmd /c ver'):. Are all 3 options still needed for the Windows versions we currently support? Are any of these specific to Win95, ..., WinXp, etc?

'command /c ver' - I think its relevant till Windows ME actually.
ver - straight from cmd.exe
cmd /c ver - will work on cmd.exe, although as i understand it intended for powershell.

I think we should remove this code completely, but if not it will be better to stay just withver

Copy link
Member

@zoobazooba left a comment

Choose a reason for hiding this comment

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

We should avoid usingctypes here, and use a native function.sys.getwindowsversion already exists and is already used in this code, and WMI gets the most accurate result and is tried first.

There is no need for this change, but at the very least, it should not usectypes and should not use kernel mode APIs when user mode ones exist.

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@zooba
Copy link
Member

That said, the actual executable that is run could be improved. Explicitly launchingcmd /C ver seems best to me - the others make more assumptions that we can avoid.

@tomergert
Copy link
Author

We should avoid usingctypes here, and use a native function.sys.getwindowsversion already exists and is already used in this code, and WMI gets the most accurate result and is tried first.

There is no need for this change, but at the very least, it should not usectypes and should not use kernel mode APIs when user mode ones exist.

That said, the actual executable that is run could be improved. Explicitly launching cmd /C ver seems best to me - the others make more assumptions that we can avoid.

This is already fallback code for if WMI doesn't work, and GetVersionEx is already provided by sys.getwindowsversion. I don't think there's anything to change here.

Hmm, lemme address.

  1. Invoking process just to query what OS you run on is bad, very bad practice. Its very bad performance-wise and much worse, security-wise. if you do it 3 times (!) it even worse. That line of code was committed 23 years (!) ago. I think that either way it should be deleted completely and no process invokes should be done.

  2. GetVersionEx - There're 2 major problems with it:

    • "may be altered or unavailable for releases after Windows 8.1" (according to MSDN).
    • The compitability issue - which means this function isn't accurate enough to our purpose -
      sys_getwindowsversion_impl(PyObject*module)
  3. sys.getwindowsversion - becauseGetVersionEx cannot be trusted, it does some very long walk around, it callsGetFileVersionInfoW (on kernel32.dll) to validate the OS version. Although it probably works fine.

  4. ctypes - I'm not sure why we should avoid it. I'll be happy to hear. Anyway,ctypes is already used inside this code (android_ver).

  5. rtlGetVersion - That's not a kernel mode API. I meant the user modertlGetVersion of course.https://learn.microsoft.com/en-us/windows/win32/devnotes/rtlgetversion

After all I think that:

  1. We must remove the process invoking anyway.
  2. rtlGetVersion is accurate and efficient fallback.
  3. sys.getwindowsversion - is a possible fallback also, we can use both.

Thank you !

@zooba
Copy link
Member

zooba commentedJan 29, 2025
edited
Loading

You should propose a PR that removes the subprocess functionality then. It's already fallback code, so it doesn't need a replacement - we can simply say that if WMI fails, you won't get the version number (or you may get one that reflects the configured compatibility mode, rather than reality).

As a policy, we don't usectypes in the standard library - some distributions removectypes (to avoid all the security issues), and we want them to be able to do it. But I don't review every line of code, and not every core developer is aware of this policy, so sometimes it slips in. If it's being used elsewhere in this file, we should remove it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@hugovkhugovkhugovk left review comments

@terryjreedyterryjreedyterryjreedy left review comments

@zoobazoobazooba requested changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@tomergert@terryjreedy@zooba@hugovk

[8]ページ先頭

©2009-2025 Movatter.jp