Skip to content

Fix unitialized var access on allocation failure#297

Merged
nickva merged 2 commits into
masterfrom
fix-uninit-value
Jun 12, 2026
Merged

Fix unitialized var access on allocation failure#297
nickva merged 2 commits into
masterfrom
fix-uninit-value

Conversation

@nickva

@nickva nickva commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Fix two places where we didn't handle allocation failures. While enif_alloc_resource() blows up on allocation failure, enif_alloc() and enif_alloc_binary() don't. During encoder and decoder resource creation if small (a few KB) mallocs fail we could end up calling the resource destructor with some uninitalized flags like have_buffer.

To prevent this class of errors in the future opt to memset the encoder and decoder structure so new fields in the future are by default 0-initialized.

Thanks to @qzhuyan (William) in #296 for pointing this issue out and providing a fix.

Fix two places where we didn't handle allocation failures. While
`enif_alloc_resource()` blows up on allocation failure, `enif_alloc()` and
`enif_alloc_binary()` don't. During encoder and decoder resource creation if
small (a few KB) mallocs fail we could end up calling the resource destructor
with some uninitalized flags like `have_buffer`.

To prevent this class of errors in the future opt to memset the encoder and
decoder structure so new fields in the future are by default 0-initialized.

Thanks to @qzhuyan (William) in #296 for
pointing this issue out and providing a fix.

@davisp davisp left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

+1

@nickva nickva merged commit 6a6ccd4 into master Jun 12, 2026
24 checks passed
@nickva nickva deleted the fix-uninit-value branch June 12, 2026 22:46
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.

2 participants