Skip to content

bpo-42260: Improve error handling in _PyConfig_FromDict #23488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ _PyConfig_AsDict(const PyConfig *config)
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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down