From aa784b09a9fbbbd571130051405edeaea7c9b510 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 2 Jan 2016 14:24:56 -0600 Subject: Fix "find . -exec echo {}" segfault, and stop measuring environment space, The segfault was spotted/fixed by Daniel K. Levy back in September, and again by Isabella Parakiss yesterday. While we're there, remove the environment size measurement code (the 128k limit was lifted by linux commit b6a2fea39318, which went into 2.6.22 released July 2007). --- toys/posix/find.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/toys/posix/find.c b/toys/posix/find.c index 1e748feb..767b4009 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -55,7 +55,7 @@ config FIND GLOBALS( char **filter; struct double_list *argdata; - int topdir, xdev, depth, envsize; + int topdir, xdev, depth; time_t now; ) @@ -63,7 +63,7 @@ GLOBALS( struct exec_range { char *next, *prev; - int dir, plus, arglen, argsize, curly, namecount, namesize; + int dir, plus, arglen, argsize, curly, namecount; char **argstart; struct double_list *names; }; @@ -387,16 +387,7 @@ static int do_find(struct dirtree *new) if (!strcmp(ss[len], ";")) break; else if (!strcmp(ss[len], "{}")) { aa->curly = len; - if (!strcmp(ss[len+1], "+")) { - - // Measure environment space - if (!TT.envsize) { - char **env; - - for (env = environ; *env; env++) - TT.envsize += sizeof(char *) + strlen(*env) + 1; - TT.envsize += sizeof(char *); - } + if (ss[len+1] && !strcmp(ss[len+1], "+")) { aa->plus++; len++; break; @@ -439,17 +430,6 @@ static int do_find(struct dirtree *new) ddl = (struct double_list **)&new->parent->extra; else ddl = &aa->names; - // Is this + mode? - if (aa->plus) { - int size = sizeof(char *)+strlen(name)+1; - - // Linux caps environment space (env vars + args) at 32 4k pages. - // todo: is there a way to probe this instead of constant here? - - if (TT.envsize+aa->argsize+aa->namesize+size >= 131072) - toys.exitval |= flush_exec(new, aa); - aa->namesize += size; - } dlist_add(ddl, name); aa->namecount++; if (!aa->plus) test = flush_exec(new, aa); -- cgit v1.2.3