Skip to content

proto_handshake: fix clean-up on mkkeys() failure - #427

Merged
cperciva merged 1 commit into
masterfrom
handshakedone-fail
Jul 22, 2026
Merged

proto_handshake: fix clean-up on mkkeys() failure#427
cperciva merged 1 commit into
masterfrom
handshakedone-fail

Conversation

@gperciva

Copy link
Copy Markdown
Member

No description provided.

@gperciva gperciva closed this Jul 12, 2026
@gperciva gperciva reopened this Jul 12, 2026
@gperciva
gperciva force-pushed the handshakedone-fail branch 2 times, most recently from 80b55bb to cd0985b Compare July 12, 2026 15:59
Comment thread lib/proto/proto_handshake.c Outdated
/* Clean up. */
if ((rc = handshakefail(H)) == 0) {
/* If there's no error in the clean-up, set a default error. */
rc = -1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm less confident about this than I am most of the other recent PRs -- why don't we want handshakefail() to return -1 in more cases?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this bit isn't right. An error from proto_crypt_mkkeys means "we were unable to generate keys because we ran out of memory"; it's a fatal error. We call handshakefail in many non-fatal code paths, e.g. if the network dropped before we got DH parameters, so in the common case it will return 0, and your patch will mask the "we should exit rather than just dropping this one connection" fatal error from proto_crypt_mkkeys.

This should just be

err1:
    handshakefail(H);

    /* Failure! */
    return (-1);

Comment thread lib/proto/proto_handshake.c Outdated

err0:
err1:
/* Clean up, but we don't care if the callback succeeded or failed. */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding a comment about this? Or mention something about informing the caller?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we have a lot of "we're cleaning up from an error, there's no point checking if we had another error" paths. This might be an idiom which is worth documenting in STYLE I guess ("don't check for for failures in an error-handling path if they will not affect behaviour")? But there's definitely no point documenting it every time it happens.

@gperciva
gperciva force-pushed the handshakedone-fail branch from 159669c to d2e406d Compare July 19, 2026 02:15
Reported by:	ChronoNova
Bug bounty:	$10 ("harmless")
@gperciva

Copy link
Copy Markdown
Member Author

Rebased

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants