Subject: misc/5345: backgammon and teachgammon args processing broken
To: None <gnats-bugs@gnats.netbsd.org>
From: None <abs@mono.org>
List: netbsd-bugs
Date: 04/21/1998 23:34:09
>Number:         5345
>Category:       misc
>Synopsis:       backgammon and teachgammon args processing broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 21 23:35:01 1998
>Last-Modified:
>Originator:     David Brownlee
>Organization:
<a href="http://www.mono.org/">Monochrome</a>
>Release:        1.3.1
>Environment:
System: NetBSD lapton.anim.dreamworks.com 1.3.1 NetBSD 1.3.1 (_LAPTON_) #0: Tue Mar 24 14:27:08 PST 1998 root@lapton.anim.dreamworks.com:/usr/src/sys/arch/i386/compile/_LAPTON_ i386


>Description:
	If you answer 'y' to "Do you want the rules of the game?" in
	backgammon it calls teachgammon with a "" argument, causing
	teachgammon to fail. Fixing that then reveals that teachgammon
	will call backgammon with "","n", neither of which is valid.
	Fixing that reveals that backgammon coredumps on - options.

>How-To-Repeat:
	Run backgammon.

>Fix:
	Minimal changes to fix the above, but still allow save games to
	work.

--- backgammon/main.c.orig	Tue Apr 21 22:36:06 1998
+++ backgammon/main.c	Tue Apr 21 23:26:52 1998
@@ -170,7 +170,7 @@
 			if (yorn(0)) {
 
 				fixtty(&old);	/* restore tty */
-				execl(TEACH, "teachgammon", args, 0);
+				execl(TEACH, "teachgammon", args[0]?args:0, 0);
 
 				tflag = 0;	/* error! */
 				writel(noteach);
--- teachgammon/teach.c.orig	Tue Apr 21 23:14:27 1998
+++ teachgammon/teach.c	Tue Apr 21 23:27:06 1998
@@ -155,7 +155,7 @@
 	else
 		writec('\n');
 	fixtty(&old);
-	execl(EXEC, "backgammon", args, "n", 0);
+	execl(EXEC, "backgammon", "-n", args[0]?args:0, 0);
 	writel("Help! Backgammon program is missing\007!!\n");
 	exit(-1);
 }
--- common_source/subs.c.orig	Tue Apr 21 23:28:04 1998
+++ common_source/subs.c	Tue Apr 21 23:26:02 1998
@@ -331,7 +331,7 @@
 	 * the game is being recovered */
 
 	s = *arg;
-	while (s[0][0] == '-') {
+	while (*s && s[0][0] == '-') {
 		switch (s[0][1]) {
 
 			/* don't ask if rules or instructions needed */
>Audit-Trail:
>Unformatted: