aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-13 02:51:08 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-13 02:51:08 -0400
commite7ad411b1a8fcd7f3cdf4a81a05aa9fc19575211 (patch)
treed84996016977a48fb33f2f19f725181fe628b8ba
parent17ee646ccd25daa83dfd363ccbe247a5b93be806 (diff)
downloadbw-atari8-tools-e7ad411b1a8fcd7f3cdf4a81a05aa9fc19575211.tar.gz
listbas: avoid buffer overflow if too many spaces in LISTBAS_OPTS.
-rw-r--r--listbas.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/listbas.c b/listbas.c
index 515d264..4a6c0a8 100644
--- a/listbas.c
+++ b/listbas.c
@@ -140,10 +140,12 @@ void parse_args(int argc, char **argv, int from_env) {
}
}
+#define ENV_MAX_ARGS 64
+
/* make a fake argv and argc */
void parse_env_args(void) {
int fargc;
- char *fargv[10];
+ char *fargv[ENV_MAX_ARGS + 1];
char *env, *p;
env = getenv(ENV_OPTS);
@@ -159,6 +161,10 @@ void parse_env_args(void) {
for(p = env; *p; p++) {
if(*p == ' ' || *p == '\t') {
*p = '\0';
+ if(fargc == ENV_MAX_ARGS) {
+ fprintf(stderr, "%s: too many spaces in LISTBAS_OPTS (max %d)\n", self, ENV_MAX_ARGS - 1);
+ break;
+ }
fargv[fargc++] = p + 1;
}
}