Repository navigation
tss: Handle realloc() failure in tss_write_callback() - #11
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tss_write_callback()assigns the result ofrealloc()directly toresponse->content. Whenrealloc()fails, the data received so far is leaked and the followingmemcpy()writes toNULL + 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
e7d6ad1and from this branch) under ASan+UBSan, failing the secondrealloc()via-Wl,--wrap=realloc:memcpy()len=6, content"hello ")"hello world", return values 6 and 5)🤖 Generated with Claude Code