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

PyErr_SetFromErrno() etc should be called immediately after setting the error code #107913

Closed
Assignees
serhiy-storchaka
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@serhiy-storchaka

Description

@serhiy-storchaka

Functions likePyErr_SetFromErrno() rely on global variableerrno (actually it is thread local, but it does not matter here). They should be called immediately after using a functions which seterrno. Calling other function (likeclose()) can change the value oferrno.Py_DECREF() andPyBuffer_Release() can execute arbitrary code, in particularly the code which changes the value oferrno. EvenPyMem_Free() is not safe, because it the memory allocator can be customized.

There is the same issue withSetFromWindowsErr() and friends. If pass 0 as Windows error code, it callsGetLastError() to retrieve the global value which can be changed at that time if some functions were called beforeSetFromWindowsErr().

Most uses in the code are correct, but there are several sites in the code where some cleanup code is inserted between function which sets the error code and function which consumes it.

Two ways to resolve this issue:

  1. Reorganize the code so thatPyErr_SetFromErrno() andSetFromWindowsErr() are called immediately after function which sets the error code (not counting simple memory reads or writes). In some cases it may require duplicating the cleanup code (usually just one line).

  2. Save the error code to a local variable before executing the intermediate code and restore it after.

Linked PRs

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixes3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp