Changed to conform to POSIX.2, 4.24.4: the first argument that starts with

a -, or is a ! or a (, and all subsequent arguments shall be interpreted
as an expression ...
The behavior before this change can cause a non-option (eg -owner instead
of -user) to be interpreted as a file name.  Depending on the expression
used, this could cause serious damage:

	find . -owner jtc -exec rm \{\} \;

Will delete every file.
This commit is contained in:
jtc 1993-12-29 22:00:13 +00:00
parent da46ebe7eb
commit 7c609895ee

View File

@ -33,7 +33,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)main.c 5.9 (Berkeley) 5/24/91";*/
static char rcsid[] = "$Id: main.c,v 1.2 1993/08/01 18:16:13 mycroft Exp $";
static char rcsid[] = "$Id: main.c,v 1.3 1993/12/29 22:00:13 jtc Exp $";
#endif /* not lint */
#include <sys/types.h>
@ -95,9 +95,13 @@ main(argc, argv)
argc -= optind;
argv += optind;
/* Find first option to delimit the file list. */
/* The first argument that starts with a -, or is a ! or a (, and all
* subsequent arguments shall be interpreted as an expression ...
* (POSIX.2).
*/
while (*argv) {
if (option(*argv))
if (**argv == '-' ||
((*argv)[1] == '\0' && (**argv == '!' || **argv == '(')))
break;
*p++ = *argv++;
}