Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsing imap resp-text #138

Open
yjm6560 opened this issue Aug 30, 2023 · 0 comments
Open

parsing imap resp-text #138

yjm6560 opened this issue Aug 30, 2023 · 0 comments

Comments

@yjm6560
Copy link

yjm6560 commented Aug 30, 2023

https://www.rfc-editor.org/rfc/rfc3501#section-9

response        = *(continue-req / response-data) response-done
response-done   = response-tagged / response-fatal
response-tagged = tag SP resp-cond-state CRLF
resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
                    ; Status condition
resp-text       = ["[" resp-text-code "]" SP] text

text            = 1*TEXT-CHAR
TEXT-CHAR       = <any CHAR except CR and LF>

resp-text comes after tag and status in tagged response(response-done) and it can be all characters except CR and LF.

mailio/src/imap.cpp

Lines 247 to 249 in 75db981

string line = dlg_->receive();
tag_result_response_t parsed_line = parse_tag_result(line);
parse_response(parsed_line.response);

however mailio::imap::parse_response tries to parse it and can raise exception in following example.

e.g.
mailbox name is mailbox) and gmail imap server sends it in resp-text.

$ openssl s_client -connect imap.gmail.com:993 -quiet -crlf
... # login
2 SELECT "mailbox)" # send SELECT command
# receive response
... # receive untagged response
2 OK [READ-WRITE] mailbox) selected. (Success) # tagged response. resp-text is "mailbox) selected. (Success)"

mailio::imap::parse_response tries to parse [READ-WRITE] mailbox) selected. (Success) and raise exception since parenthesis_counter is 0.

mailio/src/imap.cpp

Lines 1171 to 1178 in 75db981

case LIST_END:
{
if (atom_state_ == atom_state_t::QUOTED)
cur_token->atom +=ch;
else
{
if (parenthesis_list_counter_ == 0)
throw imap_error("Parser failure.");

this problem can occurs in untagged status response like * BYE test))) data is invalid.

in additionally, it looks there is no part checking if status is PREAUTH and BYE in untagged status response.

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

No branches or pull requests

1 participant