Subject: bin/21016: locate will try to read a directory as a database
To: None <>
From: None <>
List: netbsd-bugs
Date: 04/04/2003 22:07:23
>Number:         21016
>Category:       bin
>Synopsis:       locate will try to read a directory as a database
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 04 22:08:01 PST 2003
>Originator:     Soren Jacobsen
>Release:        NetBSD 1.6Q
System: NetBSD tempname 1.6Q NetBSD 1.6Q (GENERIC) #0: Tue Apr 1 15:45:36 PST 2003 root@tempname:/usr/obj/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
If passed a directory as a database, locate will try to use it. As of 1.10,
this isn't such a big deal, but it probably still shouldn't get as far as it

This PR submitted on behalf of
locate -d /usr/ blah
Apply the following patch (from, and ever so slightly
tweaked by me).

Index: locate.c
RCS file: /cvsroot/src/usr.bin/locate/locate/locate.c,v
retrieving revision 1.10
diff -b -u -r1.10 locate.c
--- locate.c	2003/04/03 01:20:26	1.10
+++ locate.c	2003/04/05 05:37:57
@@ -85,6 +85,7 @@
 #include <stdlib.h>
 #include <err.h>
 #include <sys/queue.h>
+#include <sys/stat.h>
 #include "locate.h"
 #include "pathnames.h"
@@ -113,9 +114,15 @@
 	FILE *fp;
 	struct locate_db *dbp;
+	struct stat s;
 	if (!(path && *path))
 		path = _PATH_FCODES;
+	stat(path,&s);
+	if (S_ISDIR(s.st_mode)) {
+		warnx("cannot use a directory as database");
+		exit(1);
+	} else
 	if ((fp = fopen(path, "r"))) {
 		dbp = NEW(struct locate_db);
 		dbp->db_fp = fp;