Skip to content

Bug when reusing CURL handle which was used for FTP download before #12367

@bug-fix0r

Description

@bug-fix0r

I did this

In short
If you reuse a CURL handle in PHP the HTTP code (CURLINFO_HTTP_CODE) may come from a previous FTP request.

Long description
I use CURL to download an FTP file in PHP. Later I reuse the handle to download an HTTPS file from a completely different host.

The HTTPS connection successfully downloads the file but the HTTP return code reported by CURL is 221 which comes from the FTP connection of the previous request.

I traced the FTP connection in Wireshark and it looks like this:

226 Transfer completed.
QUIT
221 Goodbye.

So here again what I do and what probably happens behind the scenes:

  1. I use CURL to download a file from an FTP server. CURLINFO_HTTP_CODE is 226 (everything good).
  2. CURL will leave the FTP connection open because it may be needed again later (everything good).
  3. I reuse the CURL handle to download a file from an HTTPS server of a completely different host (everything good).
  4. CURL receives the HTTP header and after that it downloads let's say 50% of the file (everything good).
  5. While the HTTP download is running, CURL decides to close the FTP connection of the previous request (everything good).
  6. The FTP server replies "221 Goodbye." This overwrites the valid HTTP code with an invalid value of a previous request (221) (not good).
  7. The HTTP download finishes but the CURLINFO_HTTP_CODE (221) is invalid and of a previous FTP request (not good).

I am using PHP 8.2.10-2ubuntu1 and curl_version() reports 8.2.1.

I reported this here because I thought it's probably more a CURL bug than a PHP bug.

I expected the following

At the end I expected CURLINFO_HTTP_CODE to report the HTTP code of the last request.

curl/libcurl version

PHP curl plugin 8.2.1

operating system

KUbuntu 23.10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions