karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3 and IMAP protocols. It is based on standard C++ 17 and Boost library.
Other
372 stars 98 forks source link

segmentation fault in imap fetch function #137

Open yjm6560 opened 1 year ago

yjm6560 commented 1 year ago

https://github.com/karastojko/mailio/blob/75db981761cdc1fbf47a48f2f8f45fa283ed3781/src/imap.cpp#L341-L347

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? https://github.com/karastojko/mailio/blob/75db981761cdc1fbf47a48f2f8f45fa283ed3781/src/imap.cpp#L445-L460

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