Bug#1002896: abcmidi: Stack based buffer overflow in the event_info_key function used by abc2midi
Package: abcmidi
Version: 20211212-1
Severity: important
Tags: security
Dear Maintainer,
There is a stack based buffer overflow in the event_info_key function from the store.c file used by abc2midi. The issues exists in the following code:
void event_info_key(key, value)
char* key;
char* value;
{
int num;
char midicmd[64];
char errmsg[80];
[...]
else {
sprintf(errmsg,"I: key \' %s\' not recognized", key);
if (quiet == -1 && silent == 0) event_error(errmsg); /* [SS] 2018-04-01 */
}
As can be seen there is errmsg buffer with size 80. Later on sprintf is used to write to this buffer without any boundary check. I wrote a small poc script for this in python:
#!/bin/python3
filecontent = b"""X:
I:""" + b"A" * 400
f = open("poc.abc", "wb")
f.write(filecontent)
f.close()
This generates a poc.abc file. When executing the current version of abc2midi as follows this leads to a stack overflow:
$ abc2midi poc.abc -o /dev/null
4.64 December 12 2021 abc2midi
Error in line-char 0-0 : Missing Number
*** buffer overflow detected ***: terminated
Aborted
Locally I fixed this issue by using snprintf as follows:
else {
snprintf(errmsg, 80, "I: key \' %s\' not recognized", key);
if (quiet == -1 && silent == 0) event_error(errmsg); /* [SS] 2018-04-01 */
}
Best regards
Kolja
-- System Information:
Debian Release: 11.0
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 5.10.0-8-amd64 (SMP w/4 CPU threads)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages abcmidi depends on:
ii libc6 2.31-13+deb11u2
abcmidi recommends no packages.
Versions of packages abcmidi suggests:
pn abcm2ps <none>
ii evince [postscript-viewer] 3.38.2-1
pn timidity | pmidi <none>
-- no debconf information
Reply to: