summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-04-28 11:07:06 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-04-28 11:07:06 (GMT)
commit871dfc41d37b02a7af6eb03028edc6702f24fd1d (patch)
treea790ec67f992917b9c1cad2fc654105d77a5c5bb /Python
parent94ba146d11869288ab3def8c7426b3b36701416a (diff)
downloadcpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.zip
cpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.tar.gz
cpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.tar.bz2
Issue #13204: Calling sys.flags.__new__ would crash the interpreter, now it raises a TypeError.
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 64de2bf..2366a8c 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1622,6 +1622,7 @@ PyObject *
_PySys_Init(void)
{
PyObject *m, *sysdict, *version_info;
+ int res;
m = PyModule_Create(&sysmodule);
if (m == NULL)
@@ -1629,7 +1630,6 @@ _PySys_Init(void)
sysdict = PyModule_GetDict(m);
#define SET_SYS_FROM_STRING_BORROW(key, value) \
do { \
- int res; \
PyObject *v = (value); \
if (v == NULL) \
return NULL; \
@@ -1640,7 +1640,6 @@ _PySys_Init(void)
} while (0)
#define SET_SYS_FROM_STRING(key, value) \
do { \
- int res; \
PyObject *v = (value); \
if (v == NULL) \
return NULL; \
@@ -1759,6 +1758,9 @@ _PySys_Init(void)
/* prevent user from creating new instances */
VersionInfoType.tp_init = NULL;
VersionInfoType.tp_new = NULL;
+ res = PyDict_DelItemString(VersionInfoType.tp_dict, "__new__");
+ if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
+ PyErr_Clear();
/* implementation */
SET_SYS_FROM_STRING("implementation", make_impl_info(version_info));
@@ -1772,7 +1774,9 @@ _PySys_Init(void)
/* prevent user from creating new instances */
FlagsType.tp_init = NULL;
FlagsType.tp_new = NULL;
-
+ res = PyDict_DelItemString(FlagsType.tp_dict, "__new__");
+ if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
+ PyErr_Clear();
#if defined(MS_WINDOWS)
/* getwindowsversion */
@@ -1783,6 +1787,9 @@ _PySys_Init(void)
/* prevent user from creating new instances */
WindowsVersionType.tp_init = NULL;
WindowsVersionType.tp_new = NULL;
+ res = PyDict_DelItemString(WindowsVersionType.tp_dict, "__new__");
+ if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
+ PyErr_Clear();
#endif
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */