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

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


Hi,

On 28.5.2022 1.19, Chris Jenkins wrote:
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.

Thanks for debugging and for the tested fix!


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

(Unfortunately I do not have Mac to check this.)

*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.

Ok, so that header change in b8b80c4d broke it.


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.

That could also explain the reported crash, which b8b80c4d6 is trying to fix.


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

Could you change your patch to use sizeof() and strlcpy() like the commit b8b80c4d6 does (to make it more robust and smaller), test that it still works, and send it to list / me?


	- Eero



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