From 7c609895ee41987953f8afa7ffdc1a3d8c4c2b15 Mon Sep 17 00:00:00 2001 From: jtc Date: Wed, 29 Dec 1993 22:00:13 +0000 Subject: [PATCH] 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. --- usr.bin/find/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/usr.bin/find/main.c b/usr.bin/find/main.c index cf5bc5a8b394..43ec3a06db0e 100644 --- a/usr.bin/find/main.c +++ b/usr.bin/find/main.c @@ -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 @@ -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++; }