Skip to content

ext/curl: Guard curl_reset(), copy and clone of a denied pushed handle - #433

Closed
iliaal wants to merge 1 commit into
promote/curl-push-deny-leakfrom
fix/curl-push-kept-null-handle
Closed

iliaal wants to merge 1 commit into
promote/curl-push-deny-leakfrom
fix/curl-push-kept-null-handle

Conversation

@iliaal

@iliaal iliaal commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Follow-up to php#23850, stacked on its branch. When a CURLMOPT_PUSHFUNCTION callback keeps the pushed handle and denies the push, libcurl frees the easy handle and the CurlHandle is left with a NULL ch->cp. curl_reset(), curl_copy_handle() and clone pass that NULL to curl_easy_reset() and curl_easy_duphandle() and segfault. This predates php#23850 (reproduced on 5714009); the other CurlHandle entry points already fail cleanly without an easy handle.

The test depends on the dtor change in php#23850: without it the kept handle's handlers leak and a debug build reports it.

Not included: curl_getinfo() with CURLINFO_CERTINFO leaks the array it initialised when curl_easy_getinfo() fails, reachable through the same kept handle. That is a separate fix.

When a CURLMOPT_PUSHFUNCTION callback keeps the pushed CurlHandle and
denies the push, libcurl frees the easy handle and the wrapper is left with
ch->cp set to NULL. curl_easy_reset() and curl_easy_duphandle() do not
accept a NULL handle, so curl_reset(), curl_copy_handle() and clone on the
kept handle crash. Skip the libcurl reset and take the existing duplication
failure exits when there is no easy handle.
@iliaal
iliaal force-pushed the fix/curl-push-kept-null-handle branch from a658f6c to a422e83 Compare October 14, 2026 11:16
@iliaal

iliaal commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#24323.

@iliaal iliaal closed this Oct 14, 2026
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.

1 participant