Module Name:    src
Committed By:   sborrill
Date:           Tue Oct 30 10:07:08 UTC 2018

Modified Files:
        src/usr.bin/find [netbsd-7]: function.c

Log Message:
Pull up the following revisions(s) (requested by mrg in ticket #1642):
        usr.bin/find/function.c:        revision 1.77

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.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.72.6.1 src/usr.bin/find/function.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/find/function.c
diff -u src/usr.bin/find/function.c:1.72 src/usr.bin/find/function.c:1.72.6.1
--- src/usr.bin/find/function.c:1.72	Sat May  4 06:29:32 2013
+++ src/usr.bin/find/function.c	Tue Oct 30 10:07:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: function.c,v 1.72 2013/05/04 06:29:32 uebayasi Exp $	*/
+/*	$NetBSD: function.c,v 1.72.6.1 2018/10/30 10:07:08 sborrill 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.72 2013/05/04 06:29:32 uebayasi Exp $");
+__RCSID("$NetBSD: function.c,v 1.72.6.1 2018/10/30 10:07:08 sborrill Exp $");
 #endif
 #endif /* not lint */
 
@@ -669,7 +669,9 @@ c_exec(char ***argvp, int isok)
 		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));
 
@@ -690,7 +692,9 @@ c_exec(char ***argvp, int isok)
 				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

Reply via email to