From cd457cd2d480fcadb7aaf6bc60c7dab1f937f607 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 25 Feb 2025 05:12:31 -0500 Subject: listamsb: sanity check program length in header, read stdin in binary mode. --- listamsb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/listamsb.c b/listamsb.c index ee0d9a1..1a0bec9 100644 --- a/listamsb.c +++ b/listamsb.c @@ -19,6 +19,10 @@ #define MAX_LINENO 63999 +/* a program bigger than this can't possibly fit into memory, + even with cart-based AMSB2 and no DOS loaded. */ +#define MAX_PROGLEN 30000 + const char *self; char pipe_command[BUFSIZ + 1] = { "a8cat" }; @@ -77,7 +81,11 @@ int read_header(void) { proglen = read_word(); - /* TODO: sanity check proglen */ + if(proglen > MAX_PROGLEN) { + fprintf(stderr, "%s: program too big (%d bytes), won't fit in Atari memory\n", + self, proglen); + } + return proglen; } @@ -212,10 +220,12 @@ void parse_args(int argc, char **argv) { } if(optind >= argc) { + freopen(NULL, "rb", stdin); infile = stdin; } else { infile = fopen(argv[optind], "rb"); if(!infile) { + fprintf(stderr, "%s: ", self); perror(argv[optind]); exit(1); } -- cgit v1.2.3