Skip to content

Commit 18820c1

Browse files
pythongh-83004: Harden msvcrt init
1 parent 3516704 commit 18820c1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

PC/msvcrtmodule.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ PyMODINIT_FUNC
609609
PyInit_msvcrt(void)
610610
{
611611
int st;
612-
PyObject *d, *version;
612+
PyObject *d;
613613
PyObject *m = PyModule_Create(&msvcrtmodule);
614614
if (m == NULL)
615615
return NULL;
@@ -659,11 +659,16 @@ PyInit_msvcrt(void)
659659

660660
/* constants for the 2010 crt versions */
661661
#if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION)
662-
version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION,
663-
_VC_CRT_MINOR_VERSION,
664-
_VC_CRT_BUILD_VERSION,
665-
_VC_CRT_RBUILD_VERSION);
666-
st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version);
662+
PyObject *version = PyUnicode_FromFormat("%d.%d.%d.%d",
663+
_VC_CRT_MAJOR_VERSION,
664+
_VC_CRT_MINOR_VERSION,
665+
_VC_CRT_BUILD_VERSION,
666+
_VC_CRT_RBUILD_VERSION);
667+
if (version == NULL) {
668+
return NULL;
669+
}
670+
st = PyModule_AddObjectRef(m, "CRT_ASSEMBLY_VERSION", version);
671+
Py_DECREF(version);
667672
if (st < 0) return NULL;
668673
#endif
669674
/* make compiler warning quiet if st is unused */

0 commit comments

Comments
 (0)