From 4064b20ecefb589d0b9290e558c0abfc5229c120 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 24 Jul 2009 13:40:25 +0000 Subject: Move the check to ensure the locate database has the minimum required size when using mmap() before invoking mmap(). This avoids a confusing error message when locate is invoked against a zero-size database after the recent change to make mmap() fail requests to map 0 bytes. Submitted by: Jaakko Heinonen jh of saunalahti dot fi Approved by: re (kensmith) MFC after: 1 week --- usr.bin/locate/locate/fastfind.c | 3 --- usr.bin/locate/locate/locate.c | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'usr.bin/locate') diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c index d9ab2d0..21148bc 100644 --- a/usr.bin/locate/locate/fastfind.c +++ b/usr.bin/locate/locate/fastfind.c @@ -154,9 +154,6 @@ fastfind /* init bigram table */ #ifdef FF_MMAP - if (len < (2*NBG)) - errx(1, "database too small: %s", database); - for (c = 0, p = bigram1, s = bigram2; c < NBG; c++, len-= 2) { p[c] = check_bigram_char(*paddr++); s[c] = check_bigram_char(*paddr++); diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c index d7529fb..67a97da 100644 --- a/usr.bin/locate/locate/locate.c +++ b/usr.bin/locate/locate/locate.c @@ -291,6 +291,8 @@ search_mmap(db, s) fstat(fd, &sb) == -1) err(1, "`%s'", db); len = sb.st_size; + if (len < (2*NBG)) + errx(1, "database too small: %s", db); if ((p = mmap((caddr_t)0, (size_t)len, PROT_READ, MAP_SHARED, -- cgit v1.1