easy handle: check validity on external calls

In each external API function passing a `CURL *` into the library, check
`GOOD_EASY_HANDLE()` if its magic is still there.

Ref: #17957
Closes #17958
This commit is contained in:
Stefan Eissing 2025-07-18 09:15:00 +02:00 committed by Daniel Stenberg
parent a15a5f4d29
commit 960fb49245
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 20 additions and 4 deletions

View File

@ -950,7 +950,11 @@ static void dupeasy_meta_freeentry(void *p)
CURL *curl_easy_duphandle(CURL *d)
{
struct Curl_easy *data = d;
struct Curl_easy *outcurl = calloc(1, sizeof(struct Curl_easy));
struct Curl_easy *outcurl = NULL;
if(!GOOD_EASY_HANDLE(data))
goto fail;
outcurl = calloc(1, sizeof(struct Curl_easy));
if(!outcurl)
goto fail;
@ -1074,6 +1078,9 @@ fail:
void curl_easy_reset(CURL *d)
{
struct Curl_easy *data = d;
if(!GOOD_EASY_HANDLE(data))
return;
Curl_req_hard_reset(&data->req, data);
Curl_hash_clean(&data->meta_hash);
@ -1213,6 +1220,8 @@ CURLcode curl_easy_recv(CURL *d, void *buffer, size_t buflen, size_t *n)
struct connectdata *c;
struct Curl_easy *data = d;
if(!GOOD_EASY_HANDLE(data))
return CURLE_BAD_FUNCTION_ARGUMENT;
if(Curl_is_in_callback(data))
return CURLE_RECURSIVE_API_CALL;
@ -1288,6 +1297,8 @@ CURLcode curl_easy_send(CURL *d, const void *buffer, size_t buflen, size_t *n)
size_t written = 0;
CURLcode result;
struct Curl_easy *data = d;
if(!GOOD_EASY_HANDLE(data))
return CURLE_BAD_FUNCTION_ARGUMENT;
if(Curl_is_in_callback(data))
return CURLE_RECURSIVE_API_CALL;

View File

@ -308,7 +308,8 @@ static void ws_dec_info(struct ws_decoder *dec, struct Curl_easy *data,
}
}
static CURLcode ws_send_raw_blocking(CURL *data, struct websocket *ws,
static CURLcode ws_send_raw_blocking(struct Curl_easy *data,
struct websocket *ws,
const char *buffer, size_t buflen);
typedef ssize_t ws_write_payload(const unsigned char *buf, size_t buflen,
@ -1155,6 +1156,8 @@ CURLcode curl_ws_recv(CURL *d, void *buffer,
*nread = 0;
*metap = NULL;
if(!GOOD_EASY_HANDLE(data))
return CURLE_BAD_FUNCTION_ARGUMENT;
if(!conn) {
/* Unhappy hack with lifetimes of transfers and connection */
@ -1288,12 +1291,12 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws,
return CURLE_OK;
}
static CURLcode ws_send_raw_blocking(CURL *d, struct websocket *ws,
static CURLcode ws_send_raw_blocking(struct Curl_easy *data,
struct websocket *ws,
const char *buffer, size_t buflen)
{
CURLcode result = CURLE_OK;
size_t nwritten;
struct Curl_easy *data = d;
(void)ws;
while(buflen) {
@ -1378,6 +1381,8 @@ CURLcode curl_ws_send(CURL *d, const void *buffer_arg,
CURLcode result = CURLE_OK;
struct Curl_easy *data = d;
if(!GOOD_EASY_HANDLE(data))
return CURLE_BAD_FUNCTION_ARGUMENT;
CURL_TRC_WS(data, "curl_ws_send(len=%zu, fragsize=%" FMT_OFF_T
", flags=%x), raw=%d",
buflen, fragsize, flags, data->set.ws_raw_mode);