bpo-42260: Improve error handling in _PyConfig_FromDict (GH-23488)

This commit is contained in:
Serhiy Storchaka 2020-11-24 14:07:32 +02:00 committed by GitHub
parent c0c23ea72b
commit 14d81dcaf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -1050,8 +1050,8 @@ fail:
static PyObject*
config_dict_get(PyObject *dict, const char *name)
{
PyObject *item = PyDict_GetItemString(dict, name);
if (item == NULL) {
PyObject *item = _PyDict_GetItemStringWithError(dict, name);
if (item == NULL && !PyErr_Occurred()) {
PyErr_Format(PyExc_ValueError, "missing config key: %s", name);
return NULL;
}
@ -1085,7 +1085,7 @@ config_dict_get_int(PyObject *dict, const char *name, int *result)
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
config_dict_invalid_type(name);
}
else {
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
config_dict_invalid_value(name);
}
return -1;
@ -1104,7 +1104,12 @@ config_dict_get_ulong(PyObject *dict, const char *name, unsigned long *result)
}
unsigned long value = PyLong_AsUnsignedLong(item);
if (value == (unsigned long)-1 && PyErr_Occurred()) {
config_dict_invalid_value(name);
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
config_dict_invalid_type(name);
}
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
config_dict_invalid_value(name);
}
return -1;
}
*result = value;