[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

floating point exception in games/boggle/mkdict (+ typo)



Hi,

if there is no interest in fixing issues in games/ please ignore this
mail (or at least drop a reply saying so). :)

Issue:
There is a possible floating point exception in mkdict, that is used
by the game boggle. Although the severity of this exception is very
low because mkdict won't be installed and is only used during
compilation without a value it shows on a nice way how strtonum()
helps to circumvent atoi() issues.

Description:
mkdict allows its user to apply a value (argv[1]). This value is
used in an integer division. There is no checking if argv[1] is
zero.

	if (argc == 2)
		n = atoi(argv[1]);
	...
			if (argc == 2 && nwords % n)
			continue;

$ ./mkdict 0
blah
Floating point exception (core dumped)

Solution:
Instead of atoi() strtonum() should be used that will also check if
the value is too big for signed integer, resulting in negative
values.

--- games/boggle/mkdict/mkdict.c~	Sun Apr  2 11:28:02 2006
+++ games/boggle/mkdict/mkdict.c	Sun Apr  2 11:36:27 2006
@@ -51,12 +51,13 @@
  * Filter out words that:
  *	1) Are not completely made up of lower case letters
  *	2) Contain a 'q' not immediately followed by a 'u'
- *	3) Are less that 3 characters long
+ *	3) Are less than 3 characters long
  *	4) Are greater than MAXWORDLEN characters long
  */
 
 #include <ctype.h>
 #include <err.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -74,8 +75,11 @@
 	prev = 0;
 	current = 1;
 	buf[prev][0] = '\0';
-	if (argc == 2)
-		n = atoi(argv[1]);
+	if (argc == 2) {
+		if ((n = strtonum(argv[1], 1, INT_MAX, NULL)) == 0) {
+			errx(1, "invalid value");
+		}
+	}
 
 	for (nwords = 1;
 	    fgets(buf[current], MAXWORDLEN + 1, stdin) != NULL; ++nwords) {



Visit your host, monkey.org