svn commit: r195693 - in head: lib/libc/sys sys/vm

Jaakko Heinonen jh at saunalahti.fi
Thu Jul 23 10:45:21 UTC 2009


Hi,

On 2009-07-14, John Baldwin wrote:
>   - Change mmap() to fail requests with EINVAL that pass a length of 0.  This
>     behavior is mandated by POSIX.

After this change locate(1) gives an obscure error message for empty
database files.

Before:

$ locate -d /dev/null foo
locate: database too small: /dev/null

After:

$ locate -d /dev/null foo
locate: mmap ``/dev/null'': Invalid argument


Here's a patch to restore the behavior.

%%%
Index: usr.bin/locate/locate/locate.c
===================================================================
--- usr.bin/locate/locate/locate.c	(revision 195811)
+++ usr.bin/locate/locate/locate.c	(working copy)
@@ -292,6 +292,9 @@ search_mmap(db, s)
 		err(1, "`%s'", db);
 	len = sb.st_size;
 
+	if (len == 0)
+		errx(1, "database too small: %s", db);
+
 	if ((p = mmap((caddr_t)0, (size_t)len,
 		      PROT_READ, MAP_SHARED,
 		      fd, (off_t)0)) == MAP_FAILED)
%%%

-- 
Jaakko


More information about the svn-src-head mailing list