Skip to content

Unsafe error handling on trust store load can cause crash #1

@the-Drunken-coder

Description

@the-Drunken-coder

Issue:

In src/core/ssl.c:74-75, on failure to load the system CA database (trust store), the following code attempts to dereference (*error)->message unconditionally:

context->ssl->system_trust_db = g_tls_file_database_new(ca_bundle_file, error);

if (context->ssl->system_trust_db == NULL) {
    g_warning("FATAL: Failed to load system CA trust store from %s: %s", 
              ca_bundle_file, (*error)->message);
    g_free(context->ssl);
    context->ssl = NULL;
    return FALSE; 
}

If g_tls_file_database_new fails but does not set *error, dereferencing (*error)->message will cause a null pointer dereference crash. This results in an uncontrolled fail-open/fail-crash instead of the intended fail-closed for trust failures.

Example:

if (context->ssl->system_trust_db == NULL) {
    g_warning("FATAL: Failed to load system CA trust store from %s: %s", 
              ca_bundle_file, (*error)->message); // (*error) may be NULL here!
    g_free(context->ssl);
    context->ssl = NULL;
    return FALSE; 
}

Impact:

  • Unhandled null dereference = process crash
  • May result in service outage instead of clean abort

Suggested fix:
Add a check for the error pointer before dereferencing:

const char *err_msg = (error && *error) ? (*error)->message : "(no error set)";
g_warning("FATAL: Failed to load system CA trust store from %s: %s", ca_bundle_file, err_msg);

Fail-closed must still occur, but without risk of accessing a null pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions