summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2018-05-30 15:13:22 +0000
committerespie <espie@openbsd.org>2018-05-30 15:13:22 +0000
commitdafef2994f1f5fc207600a720bde8cecb9f0e2d6 (patch)
treeac4d694e16879f7ae0d42bcec923a2e305ad9268
parentAdd sizes for free() for octeon. (diff)
downloadwireguard-openbsd-dafef2994f1f5fc207600a720bde8cecb9f0e2d6.tar.xz
wireguard-openbsd-dafef2994f1f5fc207600a720bde8cecb9f0e2d6.zip
calling err after fgets assumes we're not at EOF.
provide sensical error messages. okay millert@
-rw-r--r--usr.bin/locate/code/locate.code.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/locate/code/locate.code.c b/usr.bin/locate/code/locate.code.c
index 030bba5cb40..3711886e8e4 100644
--- a/usr.bin/locate/code/locate.code.c
+++ b/usr.bin/locate/code/locate.code.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: locate.code.c,v 1.19 2015/11/15 07:38:29 deraadt Exp $
+ * $OpenBSD: locate.code.c,v 1.20 2018/05/30 15:13:22 espie Exp $
*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: locate.code.c,v 1.19 2015/11/15 07:38:29 deraadt Exp $
+ * $Id: locate.code.c,v 1.20 2018/05/30 15:13:22 espie Exp $
*/
/*
@@ -140,8 +140,13 @@ main(int argc, char *argv[])
err(1, "pledge");
/* First copy bigram array to stdout. */
- if (fgets(bigrams, sizeof(bigrams), fp) == NULL)
- err(1, "fgets");
+ if (fgets(bigrams, sizeof(bigrams), fp) == NULL) {
+ if (ferror(fp)) {
+ err(1, "fgets on %s", argv[0]);
+ } else {
+ errx(1, "premature end of bigram file %s", argv[0]);
+ }
+ }
if (strlen(bigrams) != BGBUFSIZE)
errx(1, "bigram array too small to build db, index more files");