Skip to content

ssls: validate input arguments in import, export, and unpack - #23062

Closed
filtede98 wants to merge 2 commits into
curl:masterfrom
filtede98:fix-ssls-input-validation
Closed

filtede98 wants to merge 2 commits into
curl:masterfrom
filtede98:fix-ssls-input-validation

Conversation

@filtede98

Copy link
Copy Markdown
Contributor

Summary

This PR hardens the SSL session ticket import/export APIs and unpacking against NULL pointer dereferences and invalid arguments:

  • curl_easy_ssls_import(): returns CURLE_BAD_FUNCTION_ARGUMENT if sdata is NULL or sdata_len is 0. Per curl_easy_ssls_import(3), sdata and sdata_len must always be provided; in release builds (NDEBUG), passing NULL previously bypassed DEBUGASSERT(buf) and crashed inside spack_dec8() trying to dereference *src. Passing sdata_len == 0 returned CURLE_READ_ERROR instead of CURLE_BAD_FUNCTION_ARGUMENT.
  • curl_easy_ssls_export(): returns CURLE_BAD_FUNCTION_ARGUMENT when export_fn is NULL.
  • Curl_ssl_session_import(): validates that sdata and sdata_len are provided before calling Curl_ssl_session_unpack().
  • Curl_ssl_session_unpack(): validates ps before initializing *ps = NULL, and validates buf and buflen before parsing.
  • Added regression test checks in tests/libtest/lib1678.c to verify that curl_easy_ssls_import() and curl_easy_ssls_export() return CURLE_BAD_FUNCTION_ARGUMENT on invalid arguments.

Return CURLE_BAD_FUNCTION_ARGUMENT when NULL or zero-length buffer arguments are provided to curl_easy_ssls_import(), or when a NULL callback is passed to curl_easy_ssls_export(). Validate pointers and length in Curl_ssl_session_unpack() before dereferencing.

Add unit test verifications in test1678.
@github-actions github-actions Bot added the tests label Sep 23, 2026
@testclutch

Copy link
Copy Markdown

Analysis of PR #23062 at 7d4a82e8:

Test 3232 failed, but it has been 76.8% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Test 3231 failed, but it has been 74.5% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR.

Generated by Testclutch

Comment thread lib/vtls/vtls_spack.c Outdated
*ps = NULL;

if(!buf || !buflen)
return CURLE_BAD_FUNCTION_ARGUMENT;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an internal function that should never be called with bad parameters. I think they are better checked with DEBUGASSERT()s that make the entire thing halt in debug builds if violated, and adds nothing to release builds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Updated to use DEBUGASSERT for the internal Curl_ssl_session_unpack() checks while keeping argument validation in the public entry points.

Replace runtime checks in Curl_ssl_session_unpack() with DEBUGASSERTs as recommended during code review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unpacking still relies on debug-only assertions and can dereference invalid pointers in release builds.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Hardens SSL session import/export and unpacking against invalid arguments, with regression coverage.

Changes:

  • Rejects missing import data and export callbacks.
  • Adds session-cache and unpacking input checks.
  • Adds invalid-argument tests.
File Description
tests/​libtest/​lib1678.c Tests invalid import/export arguments.
lib/​vtls/​vtls_spack.c Adds unpacking checks; release-safe runtime validation remains needed.
lib/​vtls/​vtls_scache.c Validates imported session data.
lib/​easy.c Validates public API arguments.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/vtls/vtls_spack.c
Comment on lines +250 to 252
DEBUGASSERT(ps);
DEBUGASSERT(buf);
DEBUGASSERT(buflen);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pff, contrary to what I just said... I say ignore the clanker.

@bagder bagder closed this in 6e5dee3 Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants