Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ac754f

Browse files
committed
Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
1 parent 8207cc7 commit 1ac754f

80 files changed

Lines changed: 159 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Modules/_bsddb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,8 @@ DL_EXPORT(void) init_bsddb(void)
50345034

50355035
/* Create the module and add the functions */
50365036
m = Py_InitModule(_bsddbModuleName, bsddb_methods);
5037+
if (m == NULL)
5038+
return;
50375039

50385040
/* Add some symbolic constants to the module */
50395041
d = PyModule_GetDict(m);

Modules/_curses_panel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ init_curses_panel(void)
462462

463463
/* Create the module and add the functions */
464464
m = Py_InitModule("_curses_panel", PyCurses_methods);
465+
if (m == NULL)
466+
return;
465467
d = PyModule_GetDict(m);
466468

467469
/* For exception _curses_panel.error */

Modules/_cursesmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,8 @@ init_curses(void)
24812481

24822482
/* Create the module and add the functions */
24832483
m = Py_InitModule("_curses", PyCurses_methods);
2484+
if (m == NULL)
2485+
return;
24842486

24852487
/* Add some symbolic constants to the module */
24862488
d = PyModule_GetDict(m);

Modules/_elementtree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,8 @@ init_elementtree(void)
25902590
#endif
25912591

25922592
m = Py_InitModule("_elementtree", _functions);
2593+
if (m == NULL)
2594+
return;
25932595

25942596
/* python glue code */
25952597

Modules/_heapqmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ init_heapq(void)
610610
PyObject *m;
611611

612612
m = Py_InitModule3("_heapq", heapq_methods, module_doc);
613+
if (m == NULL)
614+
return;
613615
PyModule_AddObject(m, "__about__", PyString_FromString(__about__));
614616
}
615617

Modules/_localemodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ init_locale(void)
715715
#endif
716716

717717
m = Py_InitModule("_locale", PyLocale_Methods);
718+
if (m == NULL)
719+
return;
718720

719721
d = PyModule_GetDict(m);
720722

Modules/_randommodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ init_random(void)
573573
if (PyType_Ready(&Random_Type) < 0)
574574
return;
575575
m = Py_InitModule3("_random", NULL, module_doc);
576+
if (m == NULL)
577+
return;
576578
Py_INCREF(&Random_Type);
577579
PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
578580
}

Modules/_sre.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,6 +3389,8 @@ PyMODINIT_FUNC init_sre(void)
33893389
Scanner_Type.ob_type = &PyType_Type;
33903390

33913391
m = Py_InitModule("_" SRE_MODULE, _functions);
3392+
if (m == NULL)
3393+
return;
33923394
d = PyModule_GetDict(m);
33933395

33943396
x = PyInt_FromLong(SRE_MAGIC);

Modules/_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ init_ssl(void)
634634
PySSL_Type.ob_type = &PyType_Type;
635635

636636
m = Py_InitModule3("_ssl", PySSL_methods, module_doc);
637+
if (m == NULL)
638+
return;
637639
d = PyModule_GetDict(m);
638640

639641
/* Load _socket module and its C API */

Modules/_testcapimodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ init_testcapi(void)
627627
PyObject *m;
628628

629629
m = Py_InitModule("_testcapi", TestMethods);
630+
if (m == NULL)
631+
return;
630632

631633
PyModule_AddObject(m, "UCHAR_MAX", PyInt_FromLong(UCHAR_MAX));
632634
PyModule_AddObject(m, "USHRT_MAX", PyInt_FromLong(USHRT_MAX));

0 commit comments

Comments
 (0)