Skip to content

fix: guard croakSsl() against NULL error string#104

Merged
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-croakssl-null-deref
Mar 17, 2026
Merged

fix: guard croakSsl() against NULL error string#104
atoomic merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-croakssl-null-deref

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Mar 14, 2026

What

Prevent undefined behavior in croakSsl() when the OpenSSL error queue is empty.

Why

ERR_reason_error_string(ERR_get_error()) returns NULL when no error is queued. Passing NULL to croak()'s %s format specifier is undefined behavior per C standard — may print "(null)" on glibc but can segfault on other platforms.

This is reachable when an OpenSSL function signals failure via return value without pushing to the error queue (some EVP_PKEY operations on malformed keys, certain provider errors on OpenSSL 3.x).

How

Add a NULL guard with an "(unknown error)" fallback — single-line conditional, zero overhead on the normal path.

Testing

All 318 tests pass. The fix is defensive — it guards against a condition that's hard to trigger from Perl land but real in edge cases.

🤖 Generated with Claude Code


Quality Report

Changes: 1 file changed, 2 insertions(+), 1 deletion(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

ERR_reason_error_string() returns NULL when the OpenSSL error queue
is empty (ERR_get_error() returns 0). Passing NULL to croak's %s
format is undefined behavior — on most platforms it prints "(null)"
but it can also segfault.

This can happen when an OpenSSL function signals failure via its
return value without pushing an error to the queue (e.g. some
EVP_PKEY operations on malformed keys).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

@toddr lgtm

@atoomic atoomic marked this pull request as ready for review March 17, 2026 22:34
@atoomic atoomic merged commit 8cce9ee into cpan-authors:main Mar 17, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants