diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2020-04-09 10:27:33 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2020-04-09 10:27:33 +0000 |
commit | 2f78c65cf8ab91293f5e831cefa1a07171ba0a35 (patch) | |
tree | 281acb4b4d1238157bdb484edd34bbeb60031483 /usr.bin/find | |
parent | daa9e84e97dfba89abbf0f0b245cf7b047f00550 (diff) |
find -exec +: use sysconf to find the kernel's idea of ARG_MAX
Using ARG_MAX directly doesn't fly when ARG_MAX gets bumped and the
kernel and userland are not in sync, effectively breaking find -exec +.
Use sysconf(3) as already done in xargs(1).
Spotted by sthen@, ok deraadt@ millert@ sthen@
Diffstat (limited to 'usr.bin/find')
-rw-r--r-- | usr.bin/find/function.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 9fa052c06c4..8462dc5dec8 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.47 2019/06/28 13:35:01 deraadt Exp $ */ +/* $OpenBSD: function.c,v 1.48 2020/04/09 10:27:32 jca Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -538,7 +538,7 @@ run_f_exec(PLAN *plan) * * If -exec ... {} +, use only the first array, but make it large * enough to hold 5000 args (cf. src/usr.bin/xargs/xargs.c for a - * discussion), and then allocate ARG_MAX - 4K of space for args. + * discussion), and then allocate space for args. */ PLAN * c_exec(char *unused, char ***argvp, int isok) @@ -587,6 +587,7 @@ c_exec(char *unused, char ***argvp, int isok) errx(1, "-ok: terminating \"+\" not permitted."); if (new->flags & F_PLUSSET) { + long arg_max; u_int c, bufsize; cnt = ap - *argvp - 1; /* units are words */ @@ -599,6 +600,14 @@ c_exec(char *unused, char ***argvp, int isok) new->ep_narg = 0; /* + * Compute the maximum space we can use for arguments + * passed to execve(2). + */ + arg_max = sysconf(_SC_ARG_MAX); + if (arg_max == -1) + err(1, "sysconf(_SC_ARG_MAX) failed"); + + /* * Count up the space of the user's arguments, and * subtract that from what we allocate. */ @@ -608,8 +617,7 @@ c_exec(char *unused, char ***argvp, int isok) c += strlen(*argv) + 1; new->e_argv[cnt] = *argv; } - bufsize = ARG_MAX - 4 * 1024 - c; - + bufsize = arg_max - 4 * 1024 - c; /* * Allocate, and then initialize current, base, and |