rtrussell / BBCSDL

BBC BASIC for SDL 2.0: for Windows, Linux (86), MacOS, Raspberry Pi, Android and iOS.
zlib License
215 stars 28 forks source link

Segmentation fault on inputting long line #21

Closed Memotech-Bill closed 2 years ago

Memotech-Bill commented 2 years ago

See https://forums.raspberrypi.com/viewtopic.php?p=1940652#p1940582 for the issue.

The cause is an out-by-one error in line 2114 of bbmain.c. This line should be:

                        v.s.l = (char *) memchr (bufptr, 0x0D, 256) - bufptr ;

Changing 255 to 256.

If the input line is 255 or more characters long, then the CR is in bufptr[255], the memchr() routine does not find it and returns NULL. As a result the unsigned v.s.l contains a large value, causing a subsequent memcpy() to fail.

Memotech-Bill commented 2 years ago

Fixed in latest revision