Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/usr.bin/find Pull up following revision(s) (requested by ...
details: https://anonhg.NetBSD.org/src/rev/e264c556f8e7
branches: netbsd-8
changeset: 435253:e264c556f8e7
user: martin <martin%NetBSD.org@localhost>
date: Mon Sep 10 15:48:25 2018 +0000
description:
Pull up following revision(s) (requested by kre in ticket #1016):
usr.bin/find/function.c: revision 1.77
Inspired by PR pkg/53543
When calculating the length of the args that can be
appended in a "find .... -exec something {} +"
usage, remember to allow for the arg pointers, which
form part of what is allowed in ARG_MAX.
>From a fairly empty installation of HEAD on amd64
and with a "/tmp/args" command that simply prints
its arg count, and the length of the arg strings,
with this mod I see ..
netbsd# find / -exec /tmp/args {} +
Argc 5000 Arglen 107645
Argc 5000 Arglen 151324
Argc 5000 Arglen 187725
Argc 5000 Arglen 206591
Argc 5000 Arglen 172909
Argc 5000 Arglen 186264
Argc 5000 Arglen 167906
Argc 2881 Arglen 98260
The upper limit of 5000 args is in the code.
Using the biggest of those, 5000
args, plus 206591 bytes of strings
uses 246591 bytes total (this excludes
the command name, so add a few more).
That's fairly close to the ARG_MAX
of 262144.
On another system (with longer paths) I see:
(this is just a small part of the output, using a
different version of the dummy command, and a
slightly different invocation)
Args: 4546 Len 218030
Args: 4878 Len 217991
Args: 4813 Len 218028
Args: 4803 Len 218029
There, 4878*8 + 217991 == 257015 which is about
as close as we'd want to come to the arg limit.
XXX pullup -8
diffstat:
usr.bin/find/function.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diffs (40 lines):
diff -r 6abeb6a8aa75 -r e264c556f8e7 usr.bin/find/function.c
--- a/usr.bin/find/function.c Mon Sep 10 15:45:11 2018 +0000
+++ b/usr.bin/find/function.c Mon Sep 10 15:48:25 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: function.c,v 1.75.8.1 2017/06/15 05:46:49 snj Exp $ */
+/* $NetBSD: function.c,v 1.75.8.2 2018/09/10 15:48:25 martin Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: function.c,v 1.75.8.1 2017/06/15 05:46:49 snj Exp $");
+__RCSID("$NetBSD: function.c,v 1.75.8.2 2018/09/10 15:48:25 martin Exp $");
#endif
#endif /* not lint */
@@ -759,7 +759,9 @@
size_t c, bufsize;
cnt = ap - *argvp - 1; /* units are words */
- new->ep_maxargs = 5000;
+ new->ep_maxargs = ARG_MAX / (sizeof (char *) + 16);
+ if (new->ep_maxargs > 5000)
+ new->ep_maxargs = 5000;
new->e_argv = emalloc((cnt + new->ep_maxargs)
* sizeof(*new->e_argv));
@@ -780,7 +782,9 @@
errx(1, "Arguments too long");
new->e_argv[cnt] = *argv;
}
- bufsize = MAXARG - c;
+ if (c + new->ep_maxargs * sizeof (char *) >= MAXARG)
+ errx(1, "Arguments too long");
+ bufsize = MAXARG - c - new->ep_maxargs * sizeof (char *);
/*
* Allocate, and then initialize current, base, and
Home |
Main Index |
Thread Index |
Old Index