Skip to content

Guard against malloc failures when configure ALPN and NPN#958

Merged
normanmaurer merged 1 commit intomainfrom
malloc_failure
Mar 20, 2026
Merged

Guard against malloc failures when configure ALPN and NPN#958
normanmaurer merged 1 commit intomainfrom
malloc_failure

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

Motivation:

We missed to check for failed malloc and so could end up with a crash in the rare cause of running out of memory.

Modifications:

Add NULL checks and throw OOME

Result:

Both setNpnProtos0 and setAlpnProtos0 now check the OPENSSL_malloc return value before writing the length or calling GetByteArrayRegion.
Note that c->next_proto_len / c->alpn_proto_len is also moved to after the NULL check — previously it was written even when the allocation
had failed, which would leave the struct in an inconsistent state (non-zero length, NULL data pointer).

Motivation:

We missed to check for failed malloc and so could end up with a crash in the rare cause of running out of memory.

Modifications:

Add NULL checks and throw OOME

Result:

Both setNpnProtos0 and setAlpnProtos0 now check the OPENSSL_malloc return value before writing the length or calling GetByteArrayRegion.
Note that c->next_proto_len / c->alpn_proto_len is also moved to after the NULL check — previously it was written even when the allocation
had failed, which would leave the struct in an inconsistent state (non-zero length, NULL data pointer).
@normanmaurer normanmaurer added this to the 2.0.76.Final milestone Mar 19, 2026
@normanmaurer normanmaurer requested a review from chrisvest March 19, 2026 09:44
@normanmaurer normanmaurer merged commit 95231a7 into main Mar 20, 2026
10 checks passed
@normanmaurer normanmaurer deleted the malloc_failure branch March 20, 2026 07:14
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.

1 participant