Skip to content

Fix NULL dereference from EVP_MD_fetch() on OpenSSL 3.x#187

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-md-fetch-null-check
Draft

Fix NULL dereference from EVP_MD_fetch() on OpenSSL 3.x#187
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-md-fetch-null-check

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented May 21, 2026

What

Checks the return value of EVP_MD_fetch() in get_md_bynid() and croaks with a clear error message instead of passing NULL downstream.

Why

On OpenSSL 3.x, digest algorithms like ripemd160 and whirlpool live in the "legacy" provider, which may not be loaded at runtime. When EVP_MD_fetch() returns NULL for an unavailable algorithm, the NULL was passed directly to EVP_Digest(), causing undefined behavior or cryptic errors.

How

Refactored get_md_bynid() from per-case return statements to a name lookup + single EVP_MD_fetch() + explicit NULL check. On failure, croaks with: "Digest algorithm '%s' is not available (you may need to load the legacy provider)".

This also simplifies the function (18 insertions, 25 deletions) by eliminating the redundant EVP_MD_fetch(NULL, ..., NULL); break; pattern repeated 6-8 times.

Testing

Full test suite passes (667 tests). The fix only changes behavior when an algorithm is unavailable, which doesn't occur in standard CI environments.

🤖 Generated with Claude Code


Quality Report

Changes: 1 file changed, 18 insertions(+), 25 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

…ence

On OpenSSL 3.x, EVP_MD_fetch() can return NULL when a digest algorithm
is recognized but not available at runtime (e.g., ripemd160 or whirlpool
when the legacy provider is not loaded). Previously, get_md_bynid()
passed this NULL directly to callers, leading to undefined behavior in
EVP_Digest() or cryptic error messages.

Refactors the function to use a name lookup + single fetch + explicit
NULL check with a clear error message indicating the likely cause.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread RSA.xs
default:
croak("Unknown digest hash mode %u", hash_method);
break;
return NULL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toddr-bot do we need the return NULL here considering the croak?

Copy link
Copy Markdown
Member

@timlegge timlegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a question about the need for the return NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants