Skip to content

Commit bb043b2

Browse files
committed
skip duplicated entries if they are correct
1 parent d6a0529 commit bb043b2

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

Modules/_ssl.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6843,17 +6843,23 @@ py_ht_errcode_to_name_create(void) {
68436843
for (const py_ssl_error_code *p = error_codes; p->mnemonic != NULL; p++) {
68446844
py_ssl_errcode code = ERR_PACK(p->library, 0, p->reason);
68456845
const void *key = ssl_errcode_to_ht_key(code);
6846+
PyObject *prev = _Py_hashtable_get(table, key); /* borrowed */
6847+
if (prev != NULL) {
6848+
assert(PyUnicode_CheckExact(prev));
6849+
if (PyUnicode_EqualToUTF8(prev, p->mnemonic)) {
6850+
/* sometimes data is duplicated, so we skip it */
6851+
continue;
6852+
}
6853+
PyErr_Format(PyExc_SystemError,
6854+
"SSL data contains incompatible entries for (%d, %d). "
6855+
"Old mnemonic is %S while new mnemonic is %s",
6856+
p->library, p->reason, prev, p->mnemonic);
6857+
goto error;
6858+
}
68466859
PyObject *value = PyUnicode_FromString(p->mnemonic);
68476860
if (value == NULL) {
68486861
goto error;
68496862
}
6850-
PyObject *prev = _Py_hashtable_get(table, key); /* borrowed */
6851-
if (prev != NULL) {
6852-
PyObject *msg = PyUnicode_FromFormat("oh no for: %s (%d, %d)", p->mnemonic, p->library, p->reason);
6853-
_PyObject_Dump(msg);
6854-
Py_DECREF(msg);
6855-
_PyObject_Dump(prev);
6856-
}
68576863
if (_Py_hashtable_set(table, key, value) < 0) {
68586864
Py_DECREF(value);
68596865
goto error;
@@ -6889,17 +6895,23 @@ py_ht_libcode_to_name_create(void) {
68896895

68906896
for (const py_ssl_library_code *p = library_codes; p->library != NULL; p++) {
68916897
const void *key = ssl_errcode_to_ht_key(p->code);
6898+
PyObject *prev = _Py_hashtable_get(table, key); /* borrowed */
6899+
if (prev != NULL) {
6900+
assert(PyUnicode_CheckExact(prev));
6901+
if (PyUnicode_EqualToUTF8(prev, p->library)) {
6902+
/* sometimes data is duplicated, so we skip it */
6903+
continue;
6904+
}
6905+
PyErr_Format(PyExc_SystemError,
6906+
"SSL data contains incompatible entries for %d. "
6907+
"Old library is %S while new library is %s.",
6908+
p->code, prev, p->library);
6909+
goto error;
6910+
}
68926911
PyObject *value = PyUnicode_FromString(p->library);
68936912
if (value == NULL) {
68946913
goto error;
68956914
}
6896-
PyObject *prev = _Py_hashtable_get(table, key); /* borrowed */
6897-
if (prev != NULL) {
6898-
PyObject *msg = PyUnicode_FromFormat("oh no: %s (%d)", p->library, p->code);
6899-
_PyObject_Dump(msg);
6900-
Py_DECREF(msg);
6901-
_PyObject_Dump(prev);
6902-
}
69036915
if (_Py_hashtable_set(table, key, value) < 0) {
69046916
Py_DECREF(value);
69056917
goto error;

Tools/ssl/make_ssl_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def main():
135135
reasons.extend(parse_openssl_error_text(args))
136136
reasons.extend(parse_extra_reasons(args))
137137
# sort by libname, numeric error code
138-
args.reasons = sorted(reasons, key=operator.itemgetter(0, 3))
138+
args.reasons = sorted(set(reasons), key=operator.itemgetter(0, 3))
139139

140140
git_describe = subprocess.run(
141141
['git', 'describe', '--long', '--dirty'],

0 commit comments

Comments
 (0)