Skip to content

🥅 Guard against tagged responses sent too soon#690

Open
nevans wants to merge 5 commits into
masterfrom
guard-other-premature-tagged-responses
Open

🥅 Guard against tagged responses sent too soon#690
nevans wants to merge 5 commits into
masterfrom
guard-other-premature-tagged-responses

Conversation

@nevans

@nevans nevans commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

The premature tagged response guard that was added for #644 only checked for premature OK, not for premature BAD or NO. When those are detected prior to the tag being sent, this treats those cases as the same sort of error.

Note that this explicitly raises a "closed stream" IOError when disconnected. This is the error that would be raised anyway, if send_command were allowed to write to the connection. But, if we can test that the socket is already closed, we can raise the error directly. There's no need to attempt to format and send data. A future version will probably change this to raise a different error (subclass of Net::IMAP::Error) instead.

@nevans nevans force-pushed the guard-other-premature-tagged-responses branch from aefbd2f to ed6e9cf Compare June 8, 2026 22:43
nevans added 5 commits July 8, 2026 17:42
Combine the two error raising conditionals into a single if/elsif stmt.
Combine `#disconnect` and raise for both error handlers.
`#get_tagged_response` is called twice, from `#send_command` and
`#idle`, and both callers already handle `InvalidResponseError` by
disconnecting.
The client thread may decide to drop the connection when it sees these
exceptions:
* `InvalidResponseError` in `#send_command`
* `InvalidResponseError` in `#idle` (TODO: refactor to `#send_command`)
* _Any_ `Exception` after `#starttls` returns tagged `OK`

This saves those to an instance variable, which may be used as a cause
for other raised errors.
The premature tagged response guard that was added for #644 only checked
for premature `OK`, not for premature `BAD` or `NO`.  When those are
detected prior to the tag being sent, this treats those cases as the
same sort of error.

Note that this explicitly raises a "closed stream" IOError when
disconnected.  This is the error that would be raised anyway, if
`send_command` were allowed to write to the connection.  But, if we can
test that the socket is already closed, we can raise the error directly.
There's no need to attempt to format and send data.
@nevans nevans force-pushed the guard-other-premature-tagged-responses branch from ed6e9cf to 0841b08 Compare July 15, 2026 18:19
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.

1 participant