Skip to content

Commit 7adeff0

Browse files
authored
Update _hashopenssl.c
1 parent 65556d7 commit 7adeff0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎Modules/_hashopenssl.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ py_hashentry_t_destroy_value(void *entry) {
204204
}
205205
if (h->evp_nosecurity != NULL) {
206206
PY_EVP_MD_free(h->evp_nosecurity);
207-
h->evp_nosecurity = NULL;
207+
h->evp_nosecurity = NULL;x
208208
}
209209
PyMem_Free(entry);
210210
}
@@ -403,7 +403,10 @@ disable_fips_property(enum Py_hash_type py_ht)
403403
case Py_ht_evp_nosecurity:
404404
return 1;
405405
default:
406-
Py_FatalError("unsupported hash type");
406+
// To preserve the legacy behavior, we do not raise a fatal error here
407+
// but delegate it to a regular ValueError. This should however never
408+
// happen in practice since Py_hash_type is internal.
409+
return -1;
407410
}
408411
}
409412

@@ -415,6 +418,9 @@ py_digest_by_name(PyObject *module, const char *name, enum Py_hash_type py_ht)
415418
_hashlibstate *state = get_hashlib_state(module);
416419
py_hashentry_t *entry = _Py_hashtable_get(state->hashtable, name);
417420
int fips = disable_fips_property(py_ht);
421+
if (fips == -1) {
422+
goto finally;
423+
}
418424

419425
if (entry != NULL) {
420426
PY_EVP_MD **cached = fips ? &entry->evp : &entry->evp_nosecurity;
@@ -455,6 +461,8 @@ py_digest_by_name(PyObject *module, const char *name, enum Py_hash_type py_ht)
455461
(void)props; // will only be used in OpenSSL 3.0 and later
456462
digest = PY_EVP_MD_fetch(name, props);
457463
}
464+
465+
finally:
458466
if (digest == NULL) {
459467
raise_ssl_error(state->unsupported_digestmod_error,
460468
"unsupported hash type %s", name);

0 commit comments

Comments
 (0)