diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-26 06:43:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 06:43:39 (GMT) |
commit | fb5db7ec58624cab0797b4050735be865d380823 (patch) | |
tree | 7b0421bb759ba01f0d735296738472faa4ce11b8 /Modules/socketmodule.c | |
parent | 96a9eed2457c05af6953890d89463704c9d99c57 (diff) | |
download | cpython-fb5db7ec58624cab0797b4050735be865d380823.zip cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.gz cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.bz2 |
bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and _PyDict_GetItemId. (GH-22648)
These functions are considered not safe because they suppress all internal errors
and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can
also silence current exception in rare cases.
Remove no longer used _PyDict_GetItemId.
Add _PyDict_ContainsId and rename _PyDict_Contains into
_PyDict_Contains_KnownHash.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index db0eeaa..d773836 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -324,7 +324,7 @@ static FlagRuntimeInfo win_runtime_flags[] = { {14393, "TCP_FASTOPEN"} }; -static void +static int remove_unusable_flags(PyObject *m) { PyObject *dict; @@ -333,7 +333,7 @@ remove_unusable_flags(PyObject *m) dict = PyModule_GetDict(m); if (dict == NULL) { - return; + return -1; } /* set to Windows 10, except BuildNumber. */ @@ -359,19 +359,19 @@ remove_unusable_flags(PyObject *m) break; } else { - if (PyDict_GetItemString( - dict, - win_runtime_flags[i].flag_name) != NULL) - { - if (PyDict_DelItemString( - dict, - win_runtime_flags[i].flag_name)) - { - PyErr_Clear(); - } + PyObject *flag_name = PyUnicode_FromString(win_runtime_flags[i].flag_name); + if (flag_name == NULL) { + return -1; + } + PyObject *v = _PyDict_Pop(dict, flag_name, Py_None); + Py_DECREF(flag_name); + if (v == NULL) { + return -1; } + Py_DECREF(v); } } + return 0; } #endif @@ -8382,7 +8382,10 @@ PyInit__socket(void) #ifdef MS_WINDOWS /* remove some flags on older version Windows during run-time */ - remove_unusable_flags(m); + if (remove_unusable_flags(m) < 0) { + Py_DECREF(m); + return NULL; + } #endif return m; |