summaryrefslogtreecommitdiff
path: root/usr.bin/locate
diff options
context:
space:
mode:
authormichaels <michaels@cvs.openbsd.org>1996-10-10 09:55:09 +0000
committermichaels <michaels@cvs.openbsd.org>1996-10-10 09:55:09 +0000
commit6914174873a664fabedafba340ff51163023b4c0 (patch)
tree3be60a4d77f074b2c2eac52eb741839105d142c7 /usr.bin/locate
parent407aa2df9085e4e2bf1ef73b08cad3b46eb1146f (diff)
Fix searching for shell quoting characters. From wosch@freebsd.
Diffstat (limited to 'usr.bin/locate')
-rw-r--r--usr.bin/locate/locate/fastfind.c12
-rw-r--r--usr.bin/locate/locate/locate.h5
-rw-r--r--usr.bin/locate/locate/util.c56
3 files changed, 47 insertions, 26 deletions
diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c
index 0a8bf40315f..9f7b099f0ed 100644
--- a/usr.bin/locate/locate/fastfind.c
+++ b/usr.bin/locate/locate/fastfind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fastfind.c,v 1.1 1996/09/15 16:50:38 michaels Exp $ */
+/* $OpenBSD: fastfind.c,v 1.2 1996/10/10 09:55:06 michaels Exp $ */
/*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
@@ -36,7 +36,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fastfind.c,v 1.1 1996/09/15 16:50:38 michaels Exp $
+ * $Id: fastfind.c,v 1.2 1996/10/10 09:55:06 michaels Exp $
*/
#ifndef _LOCATE_STATISTIC_
@@ -161,8 +161,14 @@ fastfind
#endif
/* find optimal (last) char for searching */
+ for (p = pathpart; *p != '\0'; p++)
+ if (index(LOCATE_REG, *p) != NULL)
+ break;
+ if (*p == '\0')
+ globflag = 0;
+ else
+ globflag = 1;
p = pathpart;
- globflag = index(p, '*') || index(p, '?') || index(p, '[');
patend = patprep(p);
cc = *patend;
diff --git a/usr.bin/locate/locate/locate.h b/usr.bin/locate/locate/locate.h
index b169027cc3f..bc3b518fb90 100644
--- a/usr.bin/locate/locate/locate.h
+++ b/usr.bin/locate/locate/locate.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: locate.h,v 1.5 1996/09/15 16:50:39 michaels Exp $ */
+/* $OpenBSD: locate.h,v 1.6 1996/10/10 09:55:08 michaels Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -67,3 +67,6 @@ u_char myctype[UCHAR_MAX + 1];
#endif
#define INTSIZE (sizeof(int))
+
+#define LOCATE_REG "*?[]\\" /* fnmatch(3) meta characters */
+
diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c
index a3ec0e9f703..ce4c3ad90fc 100644
--- a/usr.bin/locate/locate/util.c
+++ b/usr.bin/locate/locate/util.c
@@ -1,6 +1,5 @@
-/* $OpenBSD */
-
-/*
+/* $OpenBSD: util.c,v 1.2 1996/10/10 09:55:08 michaels Exp $
+ *
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,9 +35,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: util.c,v 1.1 1996/09/15 16:50:41 michaels Exp $
+ * $Id: util.c,v 1.2 1996/10/10 09:55:08 michaels Exp $
*/
+
#include <stdlib.h>
#include <string.h>
#include <err.h>
@@ -157,31 +157,43 @@ patprep(name)
register char *endmark, *p, *subp;
subp = globfree;
- *subp++ = '\0';
+ *subp++ = '\0'; /* set first element to '\0' */
p = name + strlen(name) - 1;
- /* skip trailing metacharacters (and [] ranges) */
+
+ /* skip trailing metacharacters */
for (; p >= name; p--)
- if (index("*?", *p) == 0)
+ if (index(LOCATE_REG, *p) == NULL)
break;
- if (p < name)
- p = name;
- if (*p == ']')
- for (p--; p >= name; p--)
- if (*p == '[') {
- p--;
- break;
- }
- if (p < name)
- p = name;
- /*
- * if pattern has only metacharacters, check every path (force '/'
- * search)
+
+ /*
+ * check if maybe we are in a character class
+ *
+ * 'foo.[ch]'
+ * |----< p
*/
- if ((p == name) && index("?*[]", *p) != 0)
+ if (p >= name &&
+ (index(p, '[') != NULL || index(p, ']') != NULL)) {
+ for (p = name; *p != '\0'; p++)
+ if (*p == ']' || *p == '[')
+ break;
+ p--;
+
+ /*
+ * cannot find a non-meta character, give up
+ * '*\*[a-z]'
+ * |-------< p
+ */
+ if (p >= name && index(LOCATE_REG, *p) != NULL)
+ p = name - 1;
+ }
+
+ if (p < name)
+ /* only meta chars: "???", force '/' search */
*subp++ = '/';
+
else {
for (endmark = p; p >= name; p--)
- if (index("]*?", *p) != 0)
+ if (index(LOCATE_REG, *p) != NULL)
break;
for (++p;
(p <= endmark) && subp < (globfree + sizeof(globfree));)