Skip to content

fix: pass and receive the long values libcurl expects - #2

Merged
hzqst merged 1 commit into
mainfrom
fix/curl-long-arguments
Nov 14, 2026
Merged

hzqst merged 1 commit into
mainfrom
fix/curl-long-arguments

Conversation

@hzqst

@hzqst hzqst commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

curl_easy_getinfo(CURLINFO_RESPONSE_CODE) writes a long, but FinalizePayload passed the address of the int m_iResponseStatusCode.

  • long is 4 bytes on Windows (LLP64), so Windows was unaffected.
  • On 64-bit Linux (LP64) it is 8 bytes. HLND2T-DiligentGraphics now builds this library there. The upper half overwrote the low half of the pointer of the adjacent std::string m_ResponseErrorMessage, which sits at offset 16 right after the int at offset 12.
  • Every finished request then crashed in RunFrame while being destroyed. gdb shows the string's pointer changing from 0x5555555c99a0 to 0x555500000000 across the call, while the status code itself reads 200.

Changes in src/UtilHTTPClient_libcurl.cpp:

  • The response code is read into a long and then stored in m_iResponseStatusCode.
  • The integer curl_easy_setopt options also take a long and were passed int (1, 60000, secs * 1000) or size_t (payloadSize) through the variadic call. They now pass long: NOSIGNAL, CONNECTTIMEOUT_MS, TIMEOUT_MS, POSTFIELDSIZE, SSL_VERIFYPEER and SSL_VERIFYHOST.

Values and behavior on Windows are unchanged.

Test plan

  • Linux x86_64 smoke test (GCC 15.2, built in HLND2T-DiligentGraphics). It makes the calls the engine's download manager makes: Sys_LoadModule, CreateAsyncStreamRequest, AddToRequestPool, Send, then RunFrame until completion, against a local HTTP server.
    • Before: segmentation fault destroying the first finished request.
    • After: a 300,000-byte file arrives with status 200 and is byte-identical to the source, and a missing file reports status 404 with IsResponseError.
  • The same test under AddressSanitizer: the fixed source reports no errors; the previous source fails with SEGV in ~CUtilHTTPResponse.
  • cmake --build build/format --target format-check (clang-format 23.1.3): 4 files, 0 with differences.
  • Windows MSVC x86 build and the CTest regression suite: not run locally.

🤖 Generated with Claude Code

curl_easy_getinfo(CURLINFO_RESPONSE_CODE) writes a long, but received the address of the int m_iResponseStatusCode.
long is 4 bytes on Windows, so this was harmless there. On 64-bit Linux it is 8 bytes, and the upper half
overwrote the pointer of the adjacent std::string m_ResponseErrorMessage, so destroying any finished request
crashed. The code is now read into a long and then stored.

The integer curl_easy_setopt options (NOSIGNAL, timeouts, POSTFIELDSIZE, SSL_VERIFYPEER/HOST) also take a long and
were passed int or size_t through the variadic call; they now pass long.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hzqst
hzqst merged commit 66c04f7 into main Nov 14, 2026
3 checks passed
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