fix: Fixed UB dereference because of cast (EPROT-64) - #169
Conversation
|
It now appeared to me that *fd_ptr = fd;That value will now be lost in my commit due to This problem also exists in your |
Thank you for your contribution! Unfortunately, I missed this during my update initially. I already found this aspect as well in my MR and it is still following the formal process and needs to be fixed. The |
|
@alisitsyn Im fine with not merging this PR and it being fixed properly. Do you mean that you will adres this in your merge request on bugfix/fix_slave_error_disconnect_node? And if so, what time frame would I be looking at? Just checking if its worth it for me to wait for that fix instead of just using this for now on my local fork. |
Yes. This complete fix will be officially represented in v2.1.3 in June. Then It is better for you to use your fork for now. I will update my branch ASAP. |
Description
event_info->opt_fdis of type int16_t however it is referenced and then casted to an int*. The dereference of that int* inmb_drv_get_next_node_from_setcould (and did) cause undefined behavior.When an error has occured, the
mbm_on_erroris called which callsmb_drv_check_node_statewith a reference ofevent_info->opt_fd, which is a int16_t and gets casted to int*. It internally callsmb_drv_get_next_node_from_setwhere thefd_ptris dereferenced and four bytes are being copied intofd. See the outcome below:Within mb_driver I have added a log as test which looks like the following:
Currently trying to merge it into bugfix/fix_slave_error_disconnected_node because this can also happen within port_tcp_slave but has been fixed there in #162. If you want me to instead merge into main, please let me know.
Related
Testing
It happens for me when a master is connected to a client and the client resets. The log above is shown and the controller crashes with a LoadProhibited. This doesn't happen anymore with the fix. I'm not really sure why we get the MB_EVENT_ERROR but that doesn't really matter.
Might be hard to reproduce because of undefined behavior doing strange things but can be seen as working in the same log but not crashing below:
Checklist
Before submitting a Pull Request, please ensure the following: