|[hatari-devel] Patch to fix crash saving midi preferences on Mac|
[ Thread Index |
| More lists.tuxfamily.org/hatari-devel Archives
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: [hatari-devel] Patch to fix crash saving midi preferences on Mac
- From: Chris Jenkins <cdpjenkins@xxxxxxxxx>
- Date: Fri, 27 May 2022 23:19:34 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=y1fv2PZMWG5MUg8NEkGscvfy34W6Xoj4+8gUDcvrY3w=; b=CH32IQx4Coz+kbnDM6Xtn8FqUhLmxpHCMpuZv/FAGvxcal3I4Oc6zvekHFQZe01nBD 8VfNbXu90pQUpuAJH/d/UncRuj0UjP7eDpNP8OHlTIW3sk4Iy3vdaAc4pdx3tsi1IHom 6E+4hHtCphBM5BiS8Jdl5xlUZl9J3+L2T9GTVMSMz8aAdIx6BVXOlaFbElgLvdQNJd3f E58U8ge3e6PKZBRcljkqENYxDs9IVIFrxdqBDt7OXZxFf5y0UbMLhDKQDhs04g8SCqwr ExedZM7zVur/8stOWT7S0zLR4aaLGE/nMYTcrZUy+YP1aMDdCA75b+2pUIBKYXkKLSei HAdQ==
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
- Preferences are saved
- 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.
Description: Binary data