diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-02-25 05:12:31 -0500 | 
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-02-25 05:12:31 -0500 | 
| commit | cd457cd2d480fcadb7aaf6bc60c7dab1f937f607 (patch) | |
| tree | b0ba0e4c1d5b83d08c0b9879bcbf76007e1ac460 | |
| parent | 5c15179a9e2f91a9cacf28192ee0e8074cee18f7 (diff) | |
| download | bw-atari8-tools-cd457cd2d480fcadb7aaf6bc60c7dab1f937f607.tar.gz | |
listamsb: sanity check program length in header, read stdin in binary mode.
| -rw-r--r-- | listamsb.c | 12 | 
1 files changed, 11 insertions, 1 deletions
| @@ -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);  		} | 
