Skip to content

timemodule.c does not handle errors on module creation #111295

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

Closed
sobolevn opened this issue Oct 25, 2023 · 1 comment
Closed

timemodule.c does not handle errors on module creation #111295

sobolevn opened this issue Oct 25, 2023 · 1 comment
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 25, 2023

Bug report

Here are the problematic lines:

cpython/Modules/timemodule.c

Lines 1766 to 1772 in 8b44f3c

PyModule_AddIntConstant(m, "timezone", _Py_timezone);
#ifdef HAVE_ALTZONE
PyModule_AddIntConstant(m, "altzone", altzone);
#else
PyModule_AddIntConstant(m, "altzone", _Py_timezone-3600);
#endif
PyModule_AddIntConstant(m, "daylight", _Py_daylight);

cpython/Modules/timemodule.c

Lines 1831 to 1833 in 8b44f3c

PyModule_AddIntConstant(m, "timezone", julyzone);
PyModule_AddIntConstant(m, "altzone", janzone);
PyModule_AddIntConstant(m, "daylight", janzone != julyzone);

cpython/Modules/timemodule.c

Lines 1836 to 1838 in 8b44f3c

PyModule_AddIntConstant(m, "timezone", janzone);
PyModule_AddIntConstant(m, "altzone", julyzone);
PyModule_AddIntConstant(m, "daylight", janzone != julyzone);

However, in some cases it uses the correct approach:

cpython/Modules/timemodule.c

Lines 1985 to 1987 in 8b44f3c

if (PyModule_AddIntMacro(module, CLOCK_MONOTONIC) < 0) {
return -1;
}

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Oct 25, 2023
@sobolevn sobolevn self-assigned this Oct 25, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 25, 2023
erlend-aasland pushed a commit that referenced this issue Oct 25, 2023
Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 25, 2023
…thonGH-111296)

Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
(cherry picked from commit 81b03e7)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
vstinner pushed a commit that referenced this issue Nov 1, 2023
…H-111296) (#111300)

gh-111295: Fix error checking in time extension module init (GH-111296)

Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
(cherry picked from commit 81b03e7)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@vstinner
Copy link
Member

vstinner commented Nov 1, 2023

Fixed in 3.12 and main branches.

@vstinner vstinner closed this as completed Nov 1, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
…thon#111296)

Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
…thon#111296)

Introduce ADD_INT macro wrapper for PyModule_AddIntConstant()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants