summaryrefslogtreecommitdiffstats
path: root/exec.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-02-10 13:37:03 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-02-10 13:37:03 -0500
commit75ad5815156efe50e6a94be3c98a058d93717a89 (patch)
tree0816a3a539cd8a2308faa8c3cc48dcbd66f62d37 /exec.c
parentf21cbfd4eaef06b5cd45455130af37b66413954c (diff)
downloadbfs-75ad5815156efe50e6a94be3c98a058d93717a89.tar.xz
exec: Fix size accounting when recovering from E2BIG
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/exec.c b/exec.c
index 3fa5789..d1503fe 100644
--- a/exec.c
+++ b/exec.c
@@ -464,6 +464,7 @@ static int bfs_exec_flush(struct bfs_exec *execbuf) {
--execbuf->argc;
}
size_t new_argc = execbuf->argc;
+ size_t new_size = execbuf->arg_size;
int error = errno;
@@ -471,23 +472,24 @@ static int bfs_exec_flush(struct bfs_exec *execbuf) {
free(execbuf->argv[i]);
}
execbuf->argc = execbuf->tmpl_argc - 1;
+ execbuf->arg_size = 0;
if (new_argc < orig_argc) {
+ execbuf->arg_max = new_size;
+ bfs_exec_debug(execbuf, "ARG_MAX: %zu\n", execbuf->arg_max);
+
// If we recovered from E2BIG, there are unused arguments at the
// end of the list
for (size_t i = new_argc + 1; i <= orig_argc; ++i) {
if (error == 0) {
execbuf->argv[execbuf->argc] = execbuf->argv[i];
+ execbuf->arg_size += bfs_exec_arg_size(execbuf->argv[execbuf->argc]);
++execbuf->argc;
} else {
free(execbuf->argv[i]);
}
}
-
- execbuf->arg_max = execbuf->arg_size;
- bfs_exec_debug(execbuf, "ARG_MAX: %zu\n", execbuf->arg_max);
}
- execbuf->arg_size = 0;
errno = error;
return ret;