Skip to content

tss: Handle realloc() failure in tss_write_callback() - #11

Merged
nikias merged 1 commit into
libimobiledevice:masterfrom
Comtea04:fix-realloc-failure
Nov 4, 2026
Merged

nikias merged 1 commit into
libimobiledevice:masterfrom
Comtea04:fix-realloc-failure

Conversation

@Comtea04

@Comtea04 Comtea04 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

tss_write_callback() assigns the result of realloc() directly to response->content. When realloc() fails, the data received so far is leaked and the following memcpy() writes to NULL + response->length.

This keeps the existing buffer on failure and returns 0, so curl aborts the transfer with CURLE_WRITE_ERROR. tss_request_send() then sees a response without a status code and handles it the same way as other incomplete responses.

Testing: ran the callback (copied verbatim from e7d6ad1 and from this branch) under ASan+UBSan, failing the second realloc() via -Wl,--wrap=realloc:

  • before: SEGV in memcpy()
  • after: returns 0, the first chunk is kept intact (len=6, content "hello ")
  • without failure: identical output before and after ("hello world", return values 6 and 5)

🤖 Generated with Claude Code

The curl write callback assigned the result of realloc() directly to
response->content, so on out-of-memory the buffer received so far was
leaked and the following memcpy() wrote through a NULL pointer.

Keep the existing buffer on failure and return 0, which makes curl
abort the transfer with CURLE_WRITE_ERROR. tss_request_send() then
handles the truncated response like any other response without a
status code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikias
nikias merged commit cdba456 into libimobiledevice:master Nov 4, 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.

2 participants