[hatari-devel] Patch to fix crash saving midi preferences on Mac

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi all,

I hit another bug after building Hatari from the latest commit on master on my Mac. Please see the attached patch that fixes it for me.

Steps to reproduce:
- Open the Mac preferences GUI
- Click OK to close the preferences GUI again

Expected results:
- Preferences are saved

Actual results:
- Hatari crashes and prints the following:
trace/BPT trap: 5

It turns out that the code is supplying the wrong size to strncpy; it supplies FILENAME_MAX (which is 1024 on my Mac) whereas the length of the field is MAX_MIDI_PORT_NAME (256). It looks like this is a similar problem to the one that was fixed in commit b8b80c4d6b8f342516479a927d831218d82cf2f0 but in a different part of the code.

Note that I didn't expect this to crash, given that the text that is being copied in this case is "Off" which isn't anywhere near 256 characters long. I guess Apple decided that their strncpy function should blow up if the size of the buffer is less than the num parameter. Running this in the debugger shows that it hits a brk instruction in a function called __chk_fail_overflow.so it looks deliberate.

Please let me know if the patch looks ok and if I can do anything else on this.

Cheers,
Chris

Attachment: 0001-Fix-crash-on-Mac-by-setting-size-of-buffer-correctly.patch
Description: Binary data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/