skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
331 stars 27 forks source link

GOSUB/GOTO on invalid lines fail. #77

Closed skx closed 5 years ago

skx commented 5 years ago

This program is an infinite loop:

 10 GOSUB 1000
 20 PRINT "OK"

The reason is that we store line/offset pairs in a map, if a line-number doesn't appear then we return 0.

In short:

 10 GOSUB 1000

Becomes:

 GOTO [offset] 0

So line 20 never gets hit.

Found via fuzzing:

     frodo ~/go/src/github.com/skx/gobasic $ cat workdir/crashers/e94d89a546f0bd779180c5a8dc969e6d4fd8a227
     10 REM This program tests that GOSUB+RETURN works

     20 GOSUB 10030
     40 GOSUB 100
     50 END

     100 PRINT "SUBROUTINE WAS CALLED!\n"
     110 RETURN
skx commented 5 years ago

https://stackoverflow.com/a/52035163 will help :)