Skip to content

userauth: reset state machine to idle on fail in userauth_password() - #2344

Closed
vszakats wants to merge 4 commits into
libssh2:masterfrom
vszakats:pw-state-machine
Closed

vszakats wants to merge 4 commits into
libssh2:masterfrom
vszakats:pw-state-machine

Conversation

@vszakats

@vszakats vszakats commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Also: reset buffer length if password change callback returned NULL.

"On the out-of-bounds early-return path, the function returns without
resetting session->userauth_pswd_state back to ssh2_NB_state_idle.
If the caller retries after this error, the state machine can continue
in sent1 with userauth_pswd_data_len == 0, leading to a misleading
follow-up LIBSSH2_ERROR_PROTO ("Unexpected packet size"). Reset the
state before returning on this failure path."

Reported by Copilot
Bug: #2224 (comment)

"On the out-of-bounds early-return path, the function returns without
resetting `session->userauth_pswd_state` back to `ssh2_NB_state_idle`.
If the caller retries after this error, the state machine can continue
in `sent1` with `userauth_pswd_data_len == 0`, leading to a misleading
follow-up `LIBSSH2_ERROR_PROTO` ("Unexpected packet size"). Reset the
state before returning on this failure path."

Reported by Copilot.
Bug: libssh2#2224 (comment)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a non-blocking state-machine bug in userauth_password() by ensuring session->userauth_pswd_state is reset to ssh2_NB_state_idle on early failure paths, preventing retries from continuing in an inconsistent intermediate state and producing misleading follow-up protocol errors.

Changes:

  • Reset session->userauth_pswd_state to ssh2_NB_state_idle when username/password bounds checks fail during the password-change flow.
  • Reset session->userauth_pswd_state to ssh2_NB_state_idle when allocation fails during the password-change flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/userauth.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@vszakats vszakats closed this in 7b1fdaa Jul 18, 2026
@vszakats
vszakats deleted the pw-state-machine branch July 18, 2026 17:57
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