aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-27 07:38:01 +0100
committerRon Yorston <rmy@pobox.com>2023-04-27 07:38:01 +0100
commit99c93b79228bb986cdeaa706f71bb1da0ec8a5fc (patch)
treed93095be727ce9ade6e7e0cc02a0d759feb23ea0
parentd0deef23fa6b228aea60b5599b5ba291ed0ad304 (diff)
downloadbusybox-w32-99c93b79228bb986cdeaa706f71bb1da0ec8a5fc.tar.gz
busybox-w32-99c93b79228bb986cdeaa706f71bb1da0ec8a5fc.tar.bz2
busybox-w32-99c93b79228bb986cdeaa706f71bb1da0ec8a5fc.zip
win32: improved error for overlong command line
Report 'Arg list too long' rather than 'Invalid argument' when spawnveq() detects that the EINVAL return from spawnve() is due to the command line being too long. Costs 48-64 bytes.
-rw-r--r--win32/process.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/win32/process.c b/win32/process.c
index 5dc0f7080..5c818a3c0 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -189,6 +189,7 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env)
189 int i, argc; 189 int i, argc;
190 intptr_t ret; 190 intptr_t ret;
191 struct stat st; 191 struct stat st;
192 size_t len = 0;
192 193
193 /* 194 /*
194 * Require that the file exists, is a regular file and is executable. 195 * Require that the file exists, is a regular file and is executable.
@@ -206,8 +207,10 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env)
206 207
207 argc = string_array_len((char **)argv); 208 argc = string_array_len((char **)argv);
208 new_argv = xzalloc(sizeof(*argv)*(argc+1)); 209 new_argv = xzalloc(sizeof(*argv)*(argc+1));
209 for (i = 0;i < argc;i++) 210 for (i = 0; i < argc; i++) {
210 new_argv[i] = quote_arg(argv[i]); 211 new_argv[i] = quote_arg(argv[i]);
212 len += strlen(new_argv[i]) + 1;
213 }
211 214
212 /* Special case: spawnve won't execute a batch file if the first 215 /* Special case: spawnve won't execute a batch file if the first
213 * argument is a relative path containing forward slashes. Absolute 216 * argument is a relative path containing forward slashes. Absolute
@@ -234,6 +237,8 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env)
234 237
235 errno = 0; 238 errno = 0;
236 ret = spawnve(mode, new_path ? new_path : path, new_argv, env); 239 ret = spawnve(mode, new_path ? new_path : path, new_argv, env);
240 if (errno == EINVAL && len > bb_arg_max())
241 errno = E2BIG;
237 242
238 done: 243 done:
239 for (i = 0;i < argc;i++) 244 for (i = 0;i < argc;i++)