The adventure game is currently broken. When it's started without
any arguments, it spits a pile of garbage to stdout before eventually
dumping its core.
The game data of adventure(6) is obfuscated at compile time with a
scheme relying on deterministic random() and deobfuscated at runtime.
This is done ``to prevent casual snooping of the executable'' (cf.
status.c). Thus the program must use the deterministic random generator
for that elaborate scheme.
Randomness during game play comes exclusively from the ran() function in
wizard.c -- which currently suffers from modulo bias -- better use
arc4random_uniform() there.
Index: init.c
===================================================================
RCS file: /cvs/src/games/adventure/init.c,v
retrieving revision 1.12
diff -u -p -r1.12 init.c
--- init.c 8 Dec 2014 21:56:27 -0000 1.12
+++ init.c 31 Dec 2014 15:11:34 -0000
@@ -56,6 +56,11 @@ int setbit[16] = {1, 2, 4, 010, 020,
void
init(void) /* everything for 1st time run */
{
+ /*
+ * We need deterministic randomness for the obfuscation schemes
+ * in io.c and setup.c.
+ */
+ srandom_deterministic(1);
rdata(); /* read data from orig. file */
linkdata();
poof();
Index: setup.c
===================================================================
RCS file: /cvs/src/games/adventure/setup.c,v
retrieving revision 1.11
diff -u -p -r1.11 setup.c
--- setup.c 8 Dec 2014 21:56:27 -0000 1.11
+++ setup.c 31 Dec 2014 15:11:34 -0000
@@ -78,6 +78,8 @@ main(int argc, char *argv[])
count = 0;
linestart = YES;
+ srandom_deterministic(1);
+
while ((c = getc(infile)) != EOF) {
if (count++ % LINE == 0)
printf("\n\t");
Index: wizard.c
===================================================================
RCS file: /cvs/src/games/adventure/wizard.c,v
retrieving revision 1.16
diff -u -p -r1.16 wizard.c
--- wizard.c 16 Nov 2014 04:49:48 -0000 1.16
+++ wizard.c 31 Dec 2014 15:11:34 -0000
@@ -141,8 +141,5 @@ ciao(void)
int
ran(int range)
{
- long i;
-
- i = random() % range;
- return (i);
+ return (arc4random_uniform(range));
}