diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-02-10 13:37:03 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-02-10 13:37:03 -0500 |
commit | 75ad5815156efe50e6a94be3c98a058d93717a89 (patch) | |
tree | 0816a3a539cd8a2308faa8c3cc48dcbd66f62d37 | |
parent | f21cbfd4eaef06b5cd45455130af37b66413954c (diff) | |
download | bfs-75ad5815156efe50e6a94be3c98a058d93717a89.tar.xz |
exec: Fix size accounting when recovering from E2BIG
-rw-r--r-- | exec.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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; |