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

segmentation fault in imap fetch function #137

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

segmentation fault in imap fetch function #137

yjm6560 opened this issue Aug 30, 2023 · 0 comments

Comments

@yjm6560
Copy link

yjm6560 commented Aug 30, 2023

mailio/src/imap.cpp

Lines 341 to 347 in 75db981

void imap::fetch(unsigned long message_no, message& msg, bool is_uid, bool header_only)
{
list<messages_range_t> messages_range;
messages_range.push_back(imap::messages_range_t(message_no, message_no));
map<unsigned long, message> found_messages;
fetch(messages_range, found_messages, is_uid, header_only, msg.line_policy());
msg = std::move(found_messages.begin()->second);

imap server doesn't send untagged response if uid or message-sequence number requested in FETCH command doesn't exist.
it sends just only tagged response with OK status in that situation.

msg = std::move(found_messages.begin()->second); 

So above code line can generate segmentation fault since it trys to access found_messages.begin() even though there is no element in it.

How about moving the logic which checks if the uid data exists to following handling tagged response?

mailio/src/imap.cpp

Lines 445 to 460 in 75db981

else if (parsed_line.tag == to_string(tag_))
{
if (parsed_line.result.value() == tag_result_response_t::OK)
{
has_more = false;
for (const auto& ms : msg_str)
{
message msg;
msg.line_policy(line_policy, line_policy);
msg.parse(ms.second);
found_messages.emplace(ms.first, move(msg));
}
}
else
throw imap_error("Fetching message failure.");
}

Of course, it is good to check if found_messages is empty before calling begin()

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