file: init fd to -1 to prevent close fd 0 on early failure

Spotted by Codex Security

Closes #21029
This commit is contained in:
Daniel Stenberg 2026-03-20 13:39:02 +01:00
parent 2cdb2209da
commit 0b182ae529
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -108,6 +108,8 @@ static CURLcode file_setup_connection(struct Curl_easy *data,
(void)conn;
/* allocate the FILE specific struct */
filep = curlx_calloc(1, sizeof(*filep));
if(filep)
filep->fd = -1;
if(!filep ||
Curl_meta_set(data, CURL_META_FILE_EASY, filep, file_easy_dtor))
return CURLE_OUT_OF_MEMORY;