Add missing NULL checks in public API functions#10216
Open
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
Open
Add missing NULL checks in public API functions#10216ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
Conversation
Add NULL and bounds validation to public API entry points that were missing basic argument checks. Fixes span ALPN, session cache, X509, SRP, PrivateKey ID/Label, and OBJ_obj2txt.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens argument validation at multiple public API entry points to prevent NULL dereferences and unsafe length usage across session cache persistence, X509 extension helpers, ALPN setters, SRP, private-key ID/label APIs, and OBJ_obj2txt.
Changes:
- Add/expand NULL checks in public-facing APIs (X509V3 extension creation, ALPN setters, session cache save/restore, private key ID/label setters).
- Harden buffer-length handling in
wolfSSL_OBJ_obj2txtand reset SRP salt pointer/size after free. - Fix allocation error handling in alt private key ID paths (correct
AllocDer()return check) and tighten memcpy sizing casts.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
wolfcrypt/src/srp.c |
Reset SRP salt pointer and size after freeing old salt to avoid stale state. |
src/x509.c |
Add missing NULL validation for sName in wolfSSL_X509V3_EXT_nconf. |
src/ssl_sess.c |
Add NULL checks before pointer arithmetic in session cache memsave/memrestore APIs. |
src/ssl_load.c |
Add NULL/negative-size validation for PrivateKey ID/Label APIs and fix AllocDer() failure check; adjust memcpy sizing. |
src/ssl.c |
Fix OBJ_obj2txt copy sizing to avoid OOB terminator write; add NULL checks for ALPN protos pointers. |
Comments suppressed due to low confidence (2)
src/ssl_load.c:4169
- These APIs accept
long szbut immediately cast toword32for allocation/copy. With onlysz < 0validation, values > UINT32_MAX will be truncated and the function may succeed with a silently shortened ID. Consider rejecting oversized inputs (e.g.,sz > UINT32_MAX) before casting and returning failure.
if (ctx == NULL || id == NULL || sz < 0) {
return 0;
}
/* Dispose of old private key and allocate and copy in id. */
FreeDer(&ctx->privateKey);
if (AllocCopyDer(&ctx->privateKey, id, (word32)sz, PRIVATEKEY_TYPE,
ctx->heap) != 0) {
src/ssl_load.c:4586
szis alongbut is cast toword32when passed toAllocCopyDer(). Consider validatingszis also <= UINT32_MAX (not just non-negative) to avoid truncating oversized sizes and returning success with partial data.
if (ssl == NULL || id == NULL || sz < 0) {
return 0;
}
/* Dispose of old private key if owned and allocate and copy in id. */
if (ssl->buffers.weOwnKey) {
FreeDer(&ssl->buffers.key);
#ifdef WOLFSSL_BLIND_PRIVATE_KEY
FreeDer(&ssl->buffers.keyMask);
#endif
}
if (AllocCopyDer(&ssl->buffers.key, id, (word32)sz, PRIVATEKEY_TYPE,
ssl->heap) != 0) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add NULL and bounds validation to public API entry points that
were missing basic argument checks. Fixes span ALPN, session cache,
X509, SRP, PrivateKey ID/Label, and OBJ_obj2txt.