ddovod / jet-live

c++ hot code reload for linux and macos
MIT License
411 stars 23 forks source link

fix crash when maps line without name #38

Closed Abergard closed 5 years ago

Abergard commented 5 years ago

Some of anonymous regions may be available in /proc/\<id>/maps file. It causes crash application during reloading.


This change is Reviewable

ddovod commented 5 years ago

Hi. Looks good, thanks, merging

ddovod commented 5 years ago

Could you also please post an example of regions you're talking about?

Abergard commented 5 years ago

For example the one section from my /proc/\<id>/maps

7f1e8a9f6000-7f1e8a9f7000 r--p 00026000 00:00 328848 /home/abergard/src/SFML-2.5.1/lib/libsfml-window.so.2.5.1 7f1e8a9f7000-7f1e8a9f8000 rw-p 00027000 00:00 328848 /home/abergard/src/SFML-2.5.1/lib/libsfml-window.so.2.5.1 7f1e8a9f8000-7f1e8a9f9000 rw-p 00000000 00:00 0 7f1e8aa00000-7f1e8aa27000 r-xp 00000000 00:00 149752 /lib/x86_64-linux-gnu/ld-2.27.so

For the third line the crash may occured before this fix.

7f1e8a9f8000-7f1e8a9f9000 rw-p 00000000 00:00 0

In this sample we have unmapped region without pathname. Your code here: for (int i = 0; i < 4; i++) { nameBegin = line.find(' ', nameBegin + 1); } returns std::npos which is is the largest positive value it can be hold as the size_type of string.

if (nameBegin != line.size() - 1) { region.name = line.substr(nameBegin);

and here the big kabuum occurs. nameBegin is larger than line.size() and std::out_of_range is thrown.

ddovod commented 5 years ago

Awesome, thank you very much!

Abergard commented 5 years ago

No problem, thanks for awesome library :)