summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorMoritz Jodeit <moritz@cvs.openbsd.org>2007-06-26 17:51:29 +0000
committerMoritz Jodeit <moritz@cvs.openbsd.org>2007-06-26 17:51:29 +0000
commitfa752f9e55a79b3067728ce9c892b84fcfb45839 (patch)
tree21e1e04abbf86c0db8e3550d9a1522bab6c8a1b7 /games
parent501021e65fa10e329c73465ef50c06d390f66f1a (diff)
Set shortest string count to 0 in strfile(8), if there a no strings found
and check the number of strings in fortune(6) to prevent empty fortune files to cause division by zero. Fixes PR 5514. OK miod@ ray@ deraadt@
Diffstat (limited to 'games')
-rw-r--r--games/fortune/fortune/fortune.c11
-rw-r--r--games/fortune/strfile/strfile.c10
2 files changed, 14 insertions, 7 deletions
diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c
index faa2df1f9c9..7030bd8eac6 100644
--- a/games/fortune/fortune/fortune.c
+++ b/games/fortune/fortune/fortune.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fortune.c,v 1.23 2006/09/25 06:03:29 otto Exp $ */
+/* $OpenBSD: fortune.c,v 1.24 2007/06/26 17:51:28 moritz Exp $ */
/* $NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $ */
/*-
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: fortune.c,v 1.23 2006/09/25 06:03:29 otto Exp $";
+static char rcsid[] = "$OpenBSD: fortune.c,v 1.24 2007/06/26 17:51:28 moritz Exp $";
#endif
#endif /* not lint */
@@ -529,7 +529,7 @@ over:
{
if (parent == NULL)
fprintf(stderr,
- "fortune:%s not a fortune file or directory\n",
+ "fortune: %s not a fortune file or directory\n",
path);
if (was_malloc)
free(path);
@@ -1141,6 +1141,11 @@ get_tbl(FILEDESC *fp)
fp->tbl.str_shortlen = ntohl(fp->tbl.str_shortlen);
fp->tbl.str_flags = ntohl(fp->tbl.str_flags);
(void) close(fd);
+
+ if (fp->tbl.str_numstr == 0) {
+ fprintf(stderr, "fortune: %s is empty\n", fp->path);
+ exit(1);
+ }
}
else {
zero_tbl(&fp->tbl);
diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c
index d9088958536..df47c1cb8f3 100644
--- a/games/fortune/strfile/strfile.c
+++ b/games/fortune/strfile/strfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strfile.c,v 1.14 2004/07/09 15:59:26 deraadt Exp $ */
+/* $OpenBSD: strfile.c,v 1.15 2007/06/26 17:51:28 moritz Exp $ */
/* $NetBSD: strfile.c,v 1.4 1995/04/24 12:23:09 cgd Exp $ */
/*-
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: strfile.c,v 1.14 2004/07/09 15:59:26 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: strfile.c,v 1.15 2007/06/26 17:51:28 moritz Exp $";
#endif
#endif /* not lint */
@@ -205,6 +205,8 @@ main(int ac, char *av[])
(void) fclose(inf);
Tbl.str_numstr = Num_pts - 1;
+ if (Tbl.str_numstr == 0)
+ Tbl.str_shortlen = 0;
if (Oflag)
do_order();
@@ -216,10 +218,10 @@ main(int ac, char *av[])
if (!Sflag) {
printf("\"%s\" created\n", Outfile);
- if (Num_pts == 2)
+ if (Tbl.str_numstr == 1)
puts("There was 1 string");
else
- printf("There were %ld strings\n", Num_pts - 1);
+ printf("There were %ld strings\n", Tbl.str_numstr);
printf("Longest string: %lu byte%s\n",
(unsigned long) Tbl.str_longlen,
Tbl.str_longlen == 1 ? "" : "s");