Skip to content

ws: check pointer args in curl_ws_recv - #23050

Closed
filtede98 wants to merge 1 commit into
curl:masterfrom
filtede98:fix-ws-recv-null-check
Closed

filtede98 wants to merge 1 commit into
curl:masterfrom
filtede98:fix-ws-recv-null-check

Conversation

@filtede98

Copy link
Copy Markdown
Contributor

Summary

In curl_ws_recv() (lib/ws.c), *recv = 0; and *metap = NULL; were dereferenced unconditionally at the start of the function before checking whether recv or metap are NULL, and before entering CURL_EAPI_ENTER(&guard, curl, ws_recv, &result).

Passing NULL as recv or metap (or calling with an invalid handle and NULL out-pointers) caused an immediate crash due to a NULL pointer dereference (SIGSEGV).

This patch moves pointer initialization inside the CURL_EAPI_ENTER guard and validates !recv || !metap, returning CURLE_BAD_FUNCTION_ARGUMENT if either pointer is NULL, following the precedent set for curl_easy_send() and curl_easy_recv() in f2a1535.

Return CURLE_BAD_FUNCTION_ARGUMENT when NULL has been passed as 'recv'
or 'metap' to curl_ws_recv(), and initialize the output values only
after validating pointers inside the API guard.

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

Address the output-initialization regression and add regression tests.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR hardens curl_ws_recv() against NULL output-pointer dereferences.

Changes:

  • Moves output initialization inside the API guard.
  • Validates output pointers and returns CURLE_BAD_FUNCTION_ARGUMENT.
File Review
lib/​ws.c Moderate issue: output parameters may remain uncleared for invalid buffers. Nit: add regression coverage for NULL pointers and handles.

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

Comment thread lib/ws.c Resolved
@testclutch

Copy link
Copy Markdown

Analysis of PR #23050 at ef72aa89:

Test 1041 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 12 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 (2, 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

@jay jay closed this in a23a600 Oct 2, 2026
@jay

jay commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants