Repository navigation
handle_server_error: don't stash a pointer into the freed message - #584
Merged
Merged
Conversation
millert
approved these changes
Oct 27, 2026
millert
left a comment
Collaborator
There was a problem hiding this comment.
It's a little unfortunate that we can't pass the relay server's error message to the client but this keeps the lifetime of errstr consistent which is more important.
Contributor
Author
|
Agreed, losing the relay's text is a shame, but it still ends up in the debug log so it isn't gone entirely. Thanks for merging this. |
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.
handle_server_error()setsclosure->errstrtomsg->u.error, a string owned by theServerMessagethathandle_server_message()just unpacked. That function frees the message withserver_message__free_unpacked()as soon as the handler returns false, andrelay_server_msg_cb()then passes the now danglingclosure->errstrtoschedule_error_message(), which packs it into the errorServerMessagesent back to the client. The error and abort strings come straight off the wire from the relay peer, so in relay mode an error or abort message makes sudo_logsrvd read freed heap and copy those bytes into its reply to the client. This came in with fcc315f, which moved the scheduling out of the handler but kept the pointer.Every other
closure->errstrin the daemon is a static translated string anderrstris never freed, so do the same here and leave the relay's own text to the debug log just above. Confirmed with AddressSanitizer by unpacking an ERRORServerMessage, aliasingu.error, freeing the message, then formatting the error reply: a heap-use-after-free read of the freed string, gone after the change.make checkpasses.