Subject: bin/6557: [PATCH] Adventure cleanup
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 12/09/1998 17:57:51
>Number:         6557
>Category:       bin
>Synopsis:       [PATCH] Adventure cleanup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Dec  9 10:20:02 1998
>Last-Modified:
>Originator:     Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-12-07
>Environment:
[
System: Linux decomino 2.0.36 #1 Mon Nov 16 14:25:34 UTC 1998 i686 unknown
Architecture: i686
]
>Description:

The patch below does some minor cleanup of adventure(6): an additional
use of const I missed in bin/6041; avoiding a signed/unsigned warning;
marking an unused parameter as such; revoking setgid privileges
(including the saved gid) rather than setuid ones; includes and
function prototypes in setup.c; the string passed to err() should not
end with a `.'.  Together with the patch sent concerning adventure's
EOF handling, this synchronises adventure(6) in NetBSD with the Linux
port of the NetBSD games.

>How-To-Repeat:

>Fix:

diff -ruN adventure/crc.c adventure+/crc.c
--- adventure/crc.c	Sun Sep 13 11:05:31 1998
+++ adventure+/crc.c	Sun Sep 13 12:24:50 1998
@@ -48,7 +48,7 @@
 
 #include "extern.h"
 
-unsigned long crctab[] = {
+const unsigned long crctab[] = {
 	0x7fffffff,
 	0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
 	0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e,
@@ -111,7 +111,7 @@
  */
 
 unsigned long crcval;
-int     step;
+unsigned int step;
 
 void
 crc_start()
diff -ruN adventure/init.c adventure+/init.c
--- adventure/init.c	Sun Aug 30 11:05:03 1998
+++ adventure+/init.c	Sun Aug 30 20:48:40 1998
@@ -217,7 +217,7 @@
 
 void
 trapdel(n)			/* come here if he hits a del */
-	int     n;
+	int     n __attribute__((__unused__));
 {
 	delhit = 1;		/* main checks, treats as QUIT */
 	signal(SIGINT, trapdel);/* catch subsequent DELs */
diff -ruN adventure/main.c adventure+/main.c
--- adventure/main.c	Mon Sep 14 11:04:46 1998
+++ adventure+/main.c	Mon Sep 14 20:31:29 1998
@@ -73,9 +73,8 @@
 	int     rval, ll;
 	struct text *kk;
 
-	/* adventure doesn't need setuid-ness, so, just get rid of it */
-	if (setuid(getuid()) < 0)
-		warn("setuid");
+	/* revoke setgid privileges */
+	setregid(getgid(), getgid());
 
 	init();		/* Initialize everything */
 	signal(SIGINT, trapdel);
diff -ruN adventure/setup.c adventure+/setup.c
--- adventure/setup.c	Mon Sep 14 11:04:46 1998
+++ adventure+/setup.c	Tue Sep 15 11:06:55 1998
@@ -64,6 +64,8 @@
 #define SIG2 " *      Sterday, 6 Thrimidge S.R. 1993, 15:24"
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
 #include "hdr.h"		/* SEED lives in there; keep them coordinated. */
 
 #define USAGE "Usage: setup file > data.c (file is typically glorkz)"
@@ -73,6 +75,8 @@
 
 #define LINE 10			/* How many values do we get on a line? */
 
+int main __P((int, char *[]));
+
 int
 main(argc, argv)
 	int     argc;
@@ -85,7 +89,7 @@
 		errx(1, USAGE);
 
 	if ((infile = fopen(argv[1], "r")) == NULL)
-		err(1, "Can't read file %s.", argv[1]);
+		err(1, "Can't read file %s", argv[1]);
 	puts("/*\n * data.c: created by setup from the ascii data file.");
 	puts(SIG1);
 	puts(SIG2);
>Audit-Trail:
>Unformatted: