Skip to content

Add missing NULL checks in public API functions#10216

Open
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
ColtonWilley:add-null-checks-public-api
Open

Add missing NULL checks in public API functions#10216
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
ColtonWilley:add-null-checks-public-api

Conversation

@ColtonWilley
Copy link
Copy Markdown
Contributor

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.

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.
@mattia-moffa mattia-moffa self-assigned this Apr 15, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 20, 2026

MemBrowse Memory Report

No memory changes detected for:

@mattia-moffa mattia-moffa marked this pull request as ready for review April 20, 2026 20:47
Copilot AI review requested due to automatic review settings April 20, 2026 20:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_obj2txt and 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 sz but immediately cast to word32 for allocation/copy. With only sz < 0 validation, 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

  • sz is a long but is cast to word32 when passed to AllocCopyDer(). Consider validating sz is 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.

Comment thread src/ssl_load.c
Comment thread src/ssl_load.c
Comment thread src/x509.c
Comment thread src/x509.c
Comment thread src/ssl.c
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