aboutsummaryrefslogtreecommitdiff
path: root/listamsb.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-02-25 05:12:31 -0500
committerB. Watson <urchlay@slackware.uk>2025-02-25 05:12:31 -0500
commitcd457cd2d480fcadb7aaf6bc60c7dab1f937f607 (patch)
treeb0ba0e4c1d5b83d08c0b9879bcbf76007e1ac460 /listamsb.c
parent5c15179a9e2f91a9cacf28192ee0e8074cee18f7 (diff)
downloadbw-atari8-tools-cd457cd2d480fcadb7aaf6bc60c7dab1f937f607.tar.gz
listamsb: sanity check program length in header, read stdin in binary mode.
Diffstat (limited to 'listamsb.c')
-rw-r--r--listamsb.c12
1 files changed, 11 insertions, 1 deletions
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);
}